joesir_1982
joesir_1982
采纳率0%
2015-04-05 09:56 阅读 2.1k

C#的adapter.update命令不能将dataset的新记录行上传进数据库

private void btn_AddBusinessInfo_Click(object sender, EventArgs e)
{
try
{
conn.Open();
ds = new DataSet();

            dap = new SqlDataAdapter("select * from BusinessInfo where State<>'删除'", conn);
            dap.Fill(ds, "BusinessInfo");

            dr = ds.Tables[0].NewRow();
            dr[1] = tb_BusinessName.Text.Trim();
            dr[2] = tb_BusinessContactName.Text.Trim();
            dr[3] = tb_BusinessTelephone.Text.Trim();
            dr[4] = tb_BusinessAddress.Text.Trim();
            dr[5] = "正常";
            ds.Tables[0].Rows.Add(dr);

            ds.AcceptChanges();
            SqlCommandBuilder scb = new SqlCommandBuilder(dap);
            dap.Update(ds, "BusinessInfo");

            dgv_BusinessInfoList.DataSource = ds.Tables[0];

            conn.Close();
        }
        catch (Exception)
        {
        }

问题描述:ds更新没有问题,DataGridView中也正确显示新记录,但是数据库中就是没有新记录,请大神审阅是哪个部分出了问题。
另参考:程序执行SqlCommandbuilder命令后,DataAdapter中没有添加InsertCommand属性![图片说明](https://img-ask.csdn.net/upload/201504/05/1428227510_312615.png)
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐