[我的ASP.net学习历程]DataBase Settion(4)

类别: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]";

OleDbConnection conn = new OleDbConnection(connectionString);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,conn);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);

DataSet ds = new DataSet();

da.Fill(ds,"List");
//记录的更新
// DataRow dr = ds.Tables["List"].Rows[1];
//
// dr.BeginEdit();
// dr["CustomerID"] = "********";
// dr["Address"] = "------";
// dr.EndEdit();
//记录更新也可写成这样!
// ds.Tables["List"].Rows[1].BeginEdit();
// ds.Tables["List"].Rows[1]["CustomerID"] = "+++++";
// ds.Tables["List"].Rows[1]["Address"] = "------";
// ds.Tables["List"].Rows[1].EndEdit();
//记录的插入
// DataRow dr = ds.Tables["List"].NewRow();
// dr["CustomerID"] = "1242354554656";
// dr["Address"] = "mmnnvbc";
//
// ds.Tables["List"].Rows.Add(dr);
//记录删除
// ds.Tables["List"].Rows[2].Delete();
//更新到数据库
da.Update(ds,"List");

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

ds.Clear();
conn.Close();

}

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