2014-09-26 82 views

回答

0

您應該使用DataAdapter.Update方法。
您沒有提供任何代碼示例,讓我告訴你這個過程的僞..

' Create the adapter with a select command text to retrieve your records' 
Dim da = new MySqlDataAdapter(selecttext, connection) 
Dim table = new DataTable() 
da.Fill(table) 

' Create a MySqlCommandBuilder to automatically generate the INSERT/UPDATE/DELETE commands' 
Dim builder = new MySqlCommandBuilder(da) 

' add the new rows to the table' 
Dim row = table.NewRow() 
..... 
table.Rows.Add(row) 

' Send the changes to the database' 
' do not call AcceptChanges before the Update' 
' otherwise every row will be in the State Unchanged ' 
' and no changes will be saved to the database' 
da.Update(table) 

您應該刪除AcceptChanges的調用。這種方法很棘手。它不會嘗試更新數據庫,但它僅用於更改已更改或已插入行的狀態,並從內存數據表中刪除已刪除的行。

相關問題