點選檢視程式碼
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=News;Integrated Security=True");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from stu", con);
SqlCommandBuilder cmdbld = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds,"stu1");
DataRow dr = ds.Tables[0].NewRow();
dr["SName"] = "小蘭";
dr["SSex"] = "女";
dr["SAge"] = 16;
ds.Tables[0].Rows.Add(dr);//新增新行
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["SName"].ToString().Equals("熊大da"))
{
ds.Tables[0].Rows.RemoveAt(i);//刪除表中SName的值為熊大da的行
}
}
da.Update(ds,"stu1");//把修改提交到資料庫
con.Close();
https://blog.csdn.net/ABC13222880223/article/details/82112308?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-4-82112308-blog-96474588.235v36pc_relevant_anti_vip&spm=1001.2101.3001.4242.3&utm_relevant_index=7