0
我必須在C#中使用基於服務的DataBase編寫通訊錄並遇到奇怪的問題。當我撥打personTableAdapter.Update(LastDataRow)
時,它會嘗試覆蓋數據庫中的身份並引發異常。使用基於服務的數據庫中的Adapter.Update()更新數據,程序試圖覆蓋身份
有沒有什麼好的方法來防止這種情況?也許迫使該計劃忽略該領域?
private DataRow LastDataRow = null;
private void UpdateRowToDatabase()
{
if (LastDataRow != null)
{
if (LastDataRow.RowState == DataRowState.Modified)
{
personTableAdapter.Update(LastDataRow);
}
}
}
private void regionBindingSource_PositionChanged(
object sender, EventArgs e)
{
BindingSource thisBindingSource =
(BindingSource)sender;
DataRow ThisDataRow =
((DataRowView)thisBindingSource.Current).Row;
if (ThisDataRow == LastDataRow)
{
throw new ApplicationException("It seems the" +
" PositionChanged event was fired twice for" +
" the same row");
}
UpdateRowToDatabase();
LastDataRow = ThisDataRow;
}
private void MainForm_FormClosed(
object sender, FormClosedEventArgs e)
{
UpdateRowToDatabase();
}
全部異常文本:http://imgur.com/buwWo7m
你可以顯示'personTableAdapter'更新查詢嗎? –
我還沒有構建任何...我使用自動生成的東西。它在github上可用。 (https://github.com/Hajtosek/CSharp/blob/master/ServiceBased%20AddressBook/AddressBookV2/DataSet1.Designer.cs)這是非常複雜的事情。 – Haito
請增加異常的全文 –