All You Need To Know About ADO.NET: Part 1/2
page 8 of 9
by Devarticles.com
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 37990/ 63

Update Method of the DataAdapter
Action is taken depending upon the value of RowState. If the value of the RowState is let us say "Modified", then the Update method automatically transmits the SQL Update statement. The transmitted SQL statement also consists of the appropriate WHERE clause so that the changes are made only to that particular record.

Create a new Windows application. Add an SqlDataAdapter, DataSet (DS11) and a form with a DataGrid and Load, Clear as well as Update buttons. In the Load buttons code, use the fill method of the DataAdapter to fill DS11 and set the DataSource property of the DataGrid to DS11.

In the clear buttons code, just set the DataSource of the DataGrid to Nothing. In the update button, call the Update method of the DataAdapter that writes the changes to the table. The code could looks something like this:

Private Sub BtnUpd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Me.SqlDataAdapter1.Update(DS11)
MsgBox("Database Updated",_ msgBoxStyle.Information, "Done")

End Sub

To test this code, follow these steps:

  1. Run the application
  2. Load the data and make some changes to the data
  3. Click the update button
  4. After the message box is displayed, clear the grid
  5. Load it once again and you will see that the changes are written to the table

View Entire Article

User Comments

Title: PC Analyst   
Name: Eddie Mathews
Date: 2006-11-27 6:23:17 PM
Comment:
I am new to Visual Studio after many years of employment in other industries. Now I want to come but I am having problem locating the Data Form Wizard. I know my installation is correct.

Thanks buddy
Title: Joe   
Name: Joseph David
Date: 2006-05-04 5:32:24 AM
Comment:
Click any Customer from the first grid and you will notice the second grid displaying records only for the selected Customer

how this work

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-27 2:19:45 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search