C#:使用DataSet上傳到數據庫

一定需要SqlCommandBuilder(sda)

SqlDataAdapter sda = new SqlDataAdapter("select * from Student", conn);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
DataRow dr = ds.Tables[0].NewRow();
dr["id"] = 2013;
dr["name"] = "劉念";
dr["course"] = "高等數學";
dr["score"] = 100;
ds.Tables[0].Rows.Add(dr);
sda.Update(ds);
ds.AcceptChanges();
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章