Does SqlDataAdapter.Update update the datatable also?
Well my issue is that I wonder if after you update the database with data from the datatable, does the datatable also get updated as well with the latest info from the database. Or do I have to do something like the following:
Dim newFilesAdptr As SqlDataAdapter = New SqlDataAdapter(newFilesCmd)
Dim newFilesBuilder As SqlCommandBuilder = New SqlCommandBuilder(newFilesAdptr)
Dim newFilesDataTable As DataTable = New DataTable
newFilesAdptr.Fill(newFilesDataTable)
'Some code
newFilesDataTable.Rows.Add(newFilesRow)
newFilesAdptr.Update(newFilesDataTable)
'Immediately get newest data
newFilesDataTable = 开发者_运维技巧Nothing
newFilesDataTable = New DataTable
newFilesAdptr.Fill(newFilesDataTable)
No - data is not synchronized back from the DB to the in-memory datatable. It effectively synchronizes the data that is in the datatable (and ONLY that data) to the actual database.
This method reads the rowstate of each datarow in the table and applies the corresponding action (update, insert, delete) to the database to reflect the changes.
Once you call Update successfully through the DataAdapter, you can call DataTable.AcceptChanges() to reset the rowstate to unchanged on all rows in the table, clearing any deleted rows and effectively synching the rows in the datatable with those in the DB, though new data in the DB is not loaded back to the datatable.
精彩评论