DataSet.AcceptChanges 方法提交然后dataAdpater. Update 更新数据库详细参考:ms-help://MS.VSCC/MS.MSDNVS.2052/Vbcon/html/vbtskupdatingrecordsindataset.htm

解决方案 »

  1.   

    SqlCommandBuilder custCB = new SqlCommandBuilder(DataAdapter);
    DataRow targetRow=dataTable.Rows[listBox1.SelectedIndex];
    DataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; Application.DoEvents();
    targetRow.BeginEdit();
    targetRow["title"]=textBox1.Text;
    targetRow.EndEdit();
    DataSet DataSetChange=dataSet.GetChanges(DataRowState.Modified);
    dataSet.Merge(DataSetChange);

    DataAdapter.Update(dataSet,"code");
    dataSet.AcceptChanges();
    Application.DoEvents();这段代码执行之后运行该过程出现错误,但是数据库里的内容却更新了。怎么回事 阿?
    错误提示:未处理的“System.Data.DBConcurrencyException”类型的异常出现在 system.data.dll 中其他信息:并发冲突:UpdateCommand 影响 0 个记录。
      

  2.   

    已经搞定,代码如下:
    try
    {
    DataAdapter.Update(dataSet ,"code");
    dataSet.AcceptChanges();
    }
    catch (DBConcurrencyException ex)
    {
    string customErrorMessage;
    customErrorMessage = ex.Message;
    customErrorMessage += ex.Row[0].ToString();
    // Replace the above code with appropriate business logic 
    // to resolve the concurrency violation.
    }