protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
Random rd = new Random();
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);
OleDbDataAdapter da = new OleDbDataAdapter(strSQL,conn);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
//通过Connection链接数据库操作,参数1为以第一行为起,参数2为向下两行止
//da.Fill(ds,1,2,"testMdb");
da.Fill(ds,"testMdb");
//向DataSet插入一新行
DataRow dr = ds.Tables["testMdb"].NewRow();
dr["CustomerID"] = "RandNumber";
dr["Address"] = rd.Next(100000).ToString();
ds.Tables["testMdb"].Rows.Add(dr);//填充内容到DataSet
da.Update(ds,"testMdb");
DataGrid1.DataSource = ds.Tables["testMdb"].DefaultView;
DataGrid1.DataBind();
ds.Clear();
conn.Close();
}