ASP.NET中用SqlDataSource控件缓存数据(2)
Visual Basic 复制代码 %@ Page language= "vb" % !-- The page uses an example configuration that includes connection strings and a defined SqlCacheDependecy. ?xml version= "1.0" ? configuration Conn
Visual Basic
复制代码

<%@ Page language="vb" %>
<!--
The page uses an example configuration that includes
connection strings and a defined SqlCacheDependecy.
<?xml version="1.0"?>
<configuration>
<ConnectionStrings>
<add name="MyNorthwind"
ConnectionString="Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind""
providerName="System.Data.SqlClient " />
</ConnectionStrings>
<system.web>
<cache>
<SqlCacheDependency enabled="true">
<databases>
<add
name="Northwind"
ConnectionStringName="MyNorthwind"
pollTime="120000" />
</databases>
</SqlCacheDependency >
</cache>
</system.web>
</configuration>
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:GridView
id="GridView1"
runat="server"
datasourceid="SqlDataSource1" />
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="SELECT EmployeeID,FirstName,Lastname FROM Employees"
EnableCaching="True"
CacheDuration="300"
CacheExpirationPolicy="Absolute"
SqlCacheDependency ="Northwind:Employees" />
</form>
</body>
</html>
<!--
The page uses an example configuration that includes
connection strings and a defined SqlCacheDependecy.
<?xml version="1.0"?>
<configuration>
<ConnectionStrings>
<add name="MyNorthwind"
ConnectionString="Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind""
providerName="System.Data.SqlClient " />
</ConnectionStrings>
<system.web>
<cache>
<SqlCacheDependency enabled="true">
<databases>
<add
name="Northwind"
ConnectionStringName="MyNorthwind"
pollTime="120000" />
</databases>
</SqlCacheDependency >
</cache>
</system.web>
</configuration>
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:GridView
id="GridView1"
runat="server"
datasourceid="SqlDataSource1" />
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="SELECT EmployeeID,FirstName,Lastname FROM Employees"
EnableCaching="True"
CacheDuration="300"
CacheExpirationPolicy="Absolute"
SqlCacheDependency ="Northwind:Employees" />
</form>
</body>
</html>
C#
复制代码

<%@ Page language="c#" %> <!-- The page uses an example configuration that includes connection strings and a defined SqlCacheDependecy. <?xml version="1.0"?> <configuration> <ConnectionStrings> <add name="MyNorthwind" ConnectionString="Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind"" providerName="System.Data.SqlClient " /> </ConnectionStrings> <system.web> <cache> <SqlCacheDependency enabled="true"> <databases> <add name="Northwind" ConnectionStringName="MyNorthwind" pollTime="120000" /> </databases> </SqlCacheDependency > </cache> </system.web> </configuration> --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:GridView id="GridView1" runat="server" datasourceid="SqlDataSource1" /> <asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyNorthwind%>" SelectCommand="SELECT EmployeeID,FirstName,Lastname FROM Employees" EnableCaching="True" CacheDuration="300" CacheExpirationPolicy="Absolute" SqlCacheDependency ="Northwind:Employees" /> </form> </body> </html>
J#
复制代码

<%@ Page language="VJ#" %> <!-- The page uses an example configuration that includes connection strings and a defined SqlCacheDependecy. <?xml version="1.0"?> <configuration> <ConnectionStrings> <add name = "NorthwindConnection" ConnectionString = "Data Source="localhost";Integrated Security="SSPI";Initial Catalog="Northwind"" /> </ConnectionStrings> <system.web> ... <cache> <SqlCacheDependency enabled="true"> <databases> <add name="Northwind_Remote" ConnectionStringName="NorthwindConnection" pollTime="120000" /> </databases> </SqlCacheDependency > </cache> </system.web> </configuration> --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head runat="server"> <title>ASP.NET Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:GridView id="GridView1" runat="server" datasourceid="SqlDataSource1" /> <asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind" SelectCommand="SELECT EmployeeID,FirstName,Lastname FROM Employees" EnableCaching="True" CacheDuration="300" CacheExpirationPolicy="Absolute" SqlCacheDependency ="Northwind_Remote:Employees" /> </form> </body> </html>
精彩图集
精彩文章