当前位置:Gxlcms >
数据库问题 >
对DataTable(或者DataSet)修改后,提交修改到数据库
对DataTable(或者DataSet)修改后,提交修改到数据库
时间:2021-07-01 10:21:17
帮助过:46人阅读
[csharp] view plain
copy
- public static void UpdateTable()
- {
- SqlConnection conn = null;
- string sql = "select *From Course";
-
- DataTable dt = null;
- DataSet ds = new DataSet();
-
- try
- {
- conn = new SqlConnection(connectionString);
- SqlDataAdapter sda = new SqlDataAdapter();
- sda.SelectCommand = new SqlCommand(sql, conn);
- SqlCommandBuilder cb = new SqlCommandBuilder(sda);
-
- conn.Open();
-
- sda.Fill(ds);
- dt = ds.Tables[0];
-
- DataRow dr = dt.NewRow();
- dr["ID"] = 1006;
- dr["Name"] = "面向对象编程";
- dr["Grade"] = "10004";
- dt.Rows.Add(dr);
-
- sda.Update(dt);
-
-
-
- dt.AcceptChanges();
- }
- catch (SqlException ex)
- { }
- finally
- {
- conn.Close();
- }
- }
对DataTable(或者DataSet)修改后,提交修改到数据库
标签:try bar state ref ade csharp comment board new