How does DataAdapter update the database data?

Source: Internet
Author: User
Tags object model visual studio
Data | Database recently just completed a previous MIS, the user's request is really more and more tricky, finally is finished. You can practice vb.net again!!!

In the Ado.net object model, the DataAdapter object's function is really joyful!

The DataAdapter object is not only a function of capturing data, but it can also help you write the updated dataset back to the backend database in batches, and it is fairly simple, as long as the update method is transferred and the DataSet and DataTable are ready to be updated.
So how did DataAdapter write the change data back to the database?
People who understand the principles of database processing may find it inconceivable that we only gave the "Select" SQL command when creating DataAdapter, and did not set SQL commands such as Insert, Update, and Delete in DataAdapter. How is this process achieved?
We know that the DataAdapter object itself has several attributes: SelectCommand, InsertCommand, UpdateCommand, DeleteCommand. When the program calls to the Update method of the DataAdapter object, it is applied to InsertCommand, UpdateCommand, and to the status of the data in the dataset, respectively. The command command for the DeleteCommand property is written back to the database.
The question again, how to generate InsertCommand, UpdateCommand, DeleteCommand attributes and to enable them to correspond to the SelectCommand command correctly write back?
There are two answers:
1, the use of Visual Studio.NET design tools generated. The following illustration:

2, through the CommandBuilder class.
If you write your own code to create a DataAdapter object, the InsertCommand properties will not be created automatically, and you can help you generate InsertCommand attributes by CommandBuilder class functionality. CommandBuilder provides a way to automatically generate a single table command, which will mediate the dataset's record updates to the background database.
The following measures:
' Update the Model field for the first record is ' MF14 '
Ds. Tables ("Mechanical tables"). Row (0) ("model") = "MF14"
' Create CommandBuilder and pass in the DataAdapter constructor parameters
Dim Combuilder as New SqlCommandBuilder (DA_YB)
' Call the DataAdapter Update method, write back the data
Da_yb. Update (Ds_yb. Tables ("Mechanical table"))


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.