你好我使用下面的代码来更新DGV在验证:DataGridView的并发冲突
private void propertyInformationDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (propertyInformationDataGridView.IsCurrentCellDirty && e.ColumnIndex.ToString() != "3")
{
propertyInformationTableAdapter.Update((newCityCollectionDataSet)propertyInformationBindingSource.DataSource);
}
}
而这种代码更新DGV和值传递给特定的表:
private void propertyInformationDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex.ToString() == "3")
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)propertyInformationDataGridView.Rows[e.RowIndex].Cells[3];
DataGridViewRow row = propertyInformationDataGridView.Rows[e.RowIndex] as DataGridViewRow;
System.Data.DataRowView SelectedRowView;
newCityCollectionDataSet.PropertyInformationRow SelectedRow;
SelectedRowView = (System.Data.DataRowView)propertyInformationBindingSource.Current;
SelectedRow = (newCityCollectionDataSet.PropertyInformationRow)SelectedRowView.Row;
if (Convert.ToBoolean(checkCell.Value) == false && propertyInformationDataGridView.IsCurrentCellDirty)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var matchedCaseNumber = (from c in dc.GetTable<PropertyInformation>()
where c.CaseNumberKey == SelectedRow.CaseNumberKey
select c).SingleOrDefault();
DateTime saveNow = DateTime.Now;
reportsSent newReport = new reportsSent();
newReport.CaseNumberKey = SelectedRow.CaseNumberKey;
dc.reportsSents.InsertOnSubmit(newReport);
matchedCaseNumber.DateFinished = saveNow;
dc.SubmitChanges();
}
}
}
会发生什么是当我单击值完成或cellvalue 3然后单击不同的单元格,例如在不同的记录上的单元格值0我得到一个错误。我明白为什么我得到这个错误,但我怎么去防止这个呢?我应该将代码从验证移到点击以便不会发生错误,或者有其他方法可以解决这个问题吗?出现错误的原因是因为我与此更新:dc.SubmitChanges();
,然后在这里再次更新:
if (propertyInformationDataGridView.IsCurrentCellDirty && e.ColumnIndex.ToString() != "3")
{
propertyInformationTableAdapter.Update((newCityCollectionDataSet)propertyInformationBindingSource.DataSource);
}
我不知道如何强制正确的数据集进行更新的情况下完成之后。
错误是:
并发冲突:在更新命令影响的预期1条记录0。
在设计师在这里显示出来:
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
[global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
public virtual int Update(newCityCollectionDataSet dataSet) {
return this.Adapter.Update(dataSet, "PropertyInformation");
感谢,
韩
始终在您的问题中包含错误消息的措词。 –