Updating a datatable
This allows you to maximize the performance of your ADO. For example, if a primary key value for an existing row is updated, and a new row has been added with the new primary key value as a foreign key, it is important to process the update before the insert. By specifying a subset of rows to be updated, you can control the order in which inserts, updates, and deletes are processed. NET application by specifying command syntax at design time and, where possible, through the use of stored procedures. For example, the following code ensures that the deleted rows of the table are processed first, then the updated rows, and then the inserted rows.
I can't imagine this is the optimal coding for data table update operations, but it might be.You must explicitly set the commands before calling event and setting the Status to Skip Current Row. NVar Char, 15, "Category Name") Dim parameter As Sql Parameter = _ adapter. For more information, see Merging Data Set Contents and Handling Data Adapter Events. The following examples demonstrate how to perform updates to modified rows by explicitly setting the Private Sub Adapter Update(By Val connection String As String) Using connection As Sql Connection = New Sql Connection( _ connection String) Dim adapter As Sql Data Adapter = New Sql Data Adapter( _ "SELECT Category ID, Category Name FROM dbo. Update Command = New Sql Command( _ "UPDATE Categories SET Category Name = @Category Name " & _ "WHERE Category ID = @Category ID", connection) adapter. Fill(category Table) Dim category Row As Data Row = category Table. The Update then refreshes the row using the value of the property. After any data is loaded back into the Data Set, the On Row Updated event is raised, allowing the user to inspect the reconciled Data Set row and any output parameters returned by the command.
After a row updates successfully, the changes to that row are accepted.
For more information, see Updating Data Sources with Data Adapters.
If INSERT, UPDATE, or DELETE statements have not been specified, the Update method generates an exception.
However, you can create a Sql Command Builder or Ole Db Command Builder object to automatically generate SQL statements for single-table updates if you set the Select Command property of a . Then, any additional SQL statements that you do not set are generated by the Command Builder.
This generation logic requires key column information to be present in the Data Set.
A typical scenario is, say you have to loop through a Data Table rows and do some calculations on the rows and delete some rows depending on the condition.