[我的ASP.net学习历程]DataAdapter操作之(二)

类别:Asp 点击:0 评论:0 推荐:
  protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
string dbPath = @"Data\dbTest.mdb";
string db = Server.MapPath (dbPath);
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db;
string strSQL = "SELECT [CustomerID],[Address] FROM Customers";

DataSet ds = new DataSet();

OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(strSQL,conn);
OleDbDataAdapter da = new OleDbDataAdapter();

//通过Command链接数据库操作
da.SelectCommand = cmd;

da.Fill(ds,"testMdb");

DataGrid1.DataSource = ds.Tables["testMdb"].DefaultView;
DataGrid1.DataBind();

}

本文地址:http://com.8s8s.com/it/it8530.htm