Update data with DataSet objects

zhaozj2021-02-12  176

Author: Name: planRED-mail: planred # 163.com

http://api.533.net/ This is my new small station, the purpose is "Beginner to Beginner" because I am also an initiator :) The "experience in the heart" is written by I.

Everyone knows that data saved by DataSet is "copy" in the original database in the server memory. So the process of updating the data with DataSet is to update the "copy", and then "original" update, according to my understanding is to overwrite "original". Specifically to the process, first, you need to find a row that needs to be updated, then assign a new value, and finally update the original database.

To find the row you need to modify, the more convenient approach is to find a value in the record, which is more convenient than using the "Line Number" "line number". To do this, first, you must specify a primary key to the database, then follow the primary key. Note that this primary key must be specified in the program, and this primary key is not necessarily the same as the primary key for your database.

Then it is the last update, of course, uses the DataAdapter's update () method to implement with CommandBuilder. It should be noted that if your database does not define the primary key, it will be wrong when the update is updated, and the returned error will be " SELECTCOMMAND does not return any key column information does not support the dynamic SQL generation of UpdateCommand. "This is because we use Update () actually generates SQL statements dynamically through CommandBuilder, and then the database operation is performed. But if you have the SQL statement when you create DataAdapter at the beginning, the CommandBuilder will not take action. This is to bear in mind.

Said so much, if you don't understand, you will look at the following procedure. This is written during my practice. There are some individual settings, such as what to record, I believe everyone will understand. Code copy box

<% @ import namespace = "system.data"%> <% @ import namespace = "system.data.oledb"%>