2017-12-02 288 views
1

我試圖讓我的程序使用事件處理程序和tableadapters將一行添加到數據庫。我可以成功添加一行到數據庫,但是當我單擊「btnRefresh」按鈕時它不會保存。這是事件處理程序的代碼。在Visual Studio中更新tableadapter數據庫

Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click 
    Try 
     Validate() 
     CarsBindingSource.EndEdit() 
     CarsTableAdapter.Update(Me.ABVDataSet.Cars) 
     MsgBox("Refreshed Successfully") 
    Catch ex As Exception 
     MsgBox("Update failed") 
    End Try 
End Sub 
+0

你叫上車表或ABVDataSet AcceptChanges的? – Steve

+0

AcceptChanges?不,我沒有。我該怎麼做,那會做什麼? –

+1

Update方法選擇要查看Cars表中每行的DataRowState的內容。 AcceptChanges將此狀態重置爲「未更改」,因此更新對這些行不做任何處理。我建議使用調試器來檢查Cars表是否包含任何DataRowState屬性不同的行,並且這些行與Unchanged – Steve

回答

0
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click Try Validate() CarsBindingSource.EndEdit() CarsTableAdapter.Update(ABVDataSet,"table_name") MsgBox("Refreshed Successfully") Catch ex As Exception MsgBox("Update failed") End Try End Sub 
相關問題