home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / aspplus / samples / cache / datacache1.aspx < prev    next >
Encoding:
Text File  |  2000-05-30  |  1.5 KB  |  66 lines

  1. <%@ Import Namespace="System.Data" %>
  2. <%@ Import Namespace="System.Data.SQL" %>
  3.  
  4. <html>
  5.  
  6.   <script language="C#" runat="server">
  7.   
  8.     void Page_Load(Object Src, EventArgs E) {
  9.  
  10.       DataView Source;
  11.  
  12.       // try to retrieve item from cache
  13.       // if it's not there, add it    
  14.         
  15.       Source = (DataView)Cache["MyDataSet"];
  16.         
  17.       if (Source == null) {
  18.         
  19.         SQLConnection myConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=pubs");
  20.         SQLDataSetCommand myCommand = new SQLDataSetCommand("select * from Authors", myConnection);
  21.             
  22.         DataSet ds = new DataSet();
  23.         myCommand.FillDataSet(ds, "Authors");
  24.  
  25.         Source = new DataView(ds.Tables[0]);
  26.         Cache["MyDataSet"] = Source;
  27.         
  28.         CacheMsg.Text = "Dataset created explicitly";       
  29.       }
  30.       else {
  31.         CacheMsg.Text = "Dataset retrieved from cache";
  32.       }
  33.  
  34.       MyDataGrid.DataSource=Source;
  35.       MyDataGrid.DataBind();
  36.     }
  37.  
  38.   </script>
  39.  
  40.   <body>
  41.   
  42.     <form method="GET" runat="server">
  43.     
  44.       <h3><font face="Verdana">Caching Data</font></h3>
  45.  
  46.       <ASP:DataGrid id="MyDataGrid" runat="server"
  47.           Width="700"
  48.           BackColor="#ccccff" 
  49.           BorderColor="black"
  50.           ShowFooter="false" 
  51.           CellPadding=3 
  52.           CellSpacing="0"
  53.           Font-Name="Verdana"
  54.           Font-Size="8pt"
  55.           HeaderStyle-BackColor="#aaaad" />
  56.           
  57.       <p>
  58.       
  59.       <i><asp:label id="CacheMsg" runat="server"/></i>
  60.     
  61.     </form>
  62.   </body>
  63. </html>
  64.  
  65.  
  66.