Using the CommandBuilder
Normally when you go about updating, deleting, or inserting data via the DataSet, you fill the dataset, make your changes to the DataSet, and then issue an explicit update (DELETE or INSERT) command. Listing 19.1 shows a typical update process:
Listing 19.1. The Update Process (19NormalUpd.vb)
Dim dbConn As SqlConnection = New SqlConnection("Data Source=localhost; Integrated Security=SSPI;Initial Catalog=northwind") Dim CustomerAdapter As SqlDataAdapter = New SqlDataAdapter ("SELECT CustomerID, ContactName FROM Customers", dbConn) CustomerAdapter.UpdateCommand=New SqlCommand ("UPDATE Customers SET ContactName=@ContactName " & _ "WHERE CustomerID = @oldCustomerID", dbConn) CustomerAdapter.UpdateCommand.Parameters.Add ... |
Get Sams Teach Yourself ADO.NET in 24 Hours now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.