Dim newRow As wilsysFixedDataSet.FormulaRow =
blend.formulaDataSet.Formula.NewFormulaRow在设置了新行的所有属性之后,将分隔行.
Console.WriteLine("Current Row State Before Added: {0}", newRow.RowState)
blend.formulaDataSet.Formula.AddFormulaRow(newRow)
Console.WriteLine("Current Row State After Added: {0}", newRow.RowState)
Console.WriteLine(blend.formulaDataSet.Formula.Contains(newRow))
blend.formulaTableAdapter.Update(blend.formulaDataSet.Formula)在尝试使用表单创建新的公式记录、将该行添加到FormulaDataTable、然后以FormulaDataTable作为参数调用FormulaDataSetTableAdapter.update()方法时,我遇到了问题。我确保了行的id属性不存在,并且设置了所有其他必需的属性,并且该行在dataTable中不存在。由于一些奇怪的原因,TableAdapter选择调用UPDATECOMMAND,正如您在下面的堆栈跟踪中看到的那样,当它应该插入时。这是为什么,我能做些什么让它用新行调用适当的方法。
这里,我在控制台上打印:- newRow.RowState,然后将newRow添加到DataTable - newRow.RowState中,然后将newRow添加到DataTable - DataTable.Contains(newRow)列表项中。
Current Row State Before Added: Detached
Current Row State After Added: Added
True 下面是在执行StackTrace (DataSetTableAdapter.update(FormulaDataTable))时接收到的以下FormulaDataTable:
System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
at RepackWPF.wilsysFixedDataSetTableAdapters.FormulaTableAdapter.Update(FormulaDataTable dataTable)
at RepackWPF.NewFormDialog.NewFormula()发布于 2017-04-26 15:27:59
结果,我能够通过“刷新”对FormulaDataSet上记录的更改(主数据集包含表头)来解决这个问题,方法是调用
FormulaDataSet.AcceptChanges()方法。在每次对FormulaDataSet进行更新调用之前,我都必须调用它。这会将RowState从修改设置为不变,并允许事务通过。
https://stackoverflow.com/questions/43572059
复制相似问题