编程语言

img bgu

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

发表于2004/9/24 8:59:00  828人阅读

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();

}
阅读全文
0 0

相关文章推荐

img
取 消
img