DB2DataReader + GridView 使用方法

 
DB2DataReader + GridView 使用方法
 

   default.aspx.cs
 
   using System;
   using System.Collections.Generic;
   using System.Web;
   using System.Web.UI;
   using System.Web.UI.WebControls;
   using System.Data;
   using IBM.Data.DB2;
 
   private void DB2DataReaderConnection()
   {
 
      String ConnectionString = "Server=<Host Name>;Database=<Database Name>;UID=<Account ID>;PWD=<Account Password>";
      DB2Connection conn = new DB2Connection(ConnectionString);
      conn.Open();
 
      String SQLStatement = "SELECT * FROM STAFF";
 
      DB2Command cmd = new DB2Command(SQLStatement, conn);
 
      DataTable dt = new DataTable();
 
      DB2DataReader dr = cmd.ExecuteReader();
 
      dt.Load(dr);
 
      GridView1.DataSource = dt;
      GridView1.DataBind();
 
      conn.Dispose();
      cmd.Dispose();
      dr.Dispose();
      dt.Dispose();
      conn.Close();
 
   }