DataTable. AcceptChanges & DataAdapter. Update

Source: Internet
Author: User

The AcceptChanges method makes rows statusUnchanged, Then the DataAdapter. update method will think there's no data modification (it will check the rows status in fact, if the status is Unchanged it will do nothing for you ), and will not update the data to the database.

So do not use the AcceptChanges method before you call DataAdapter. Update method, only the DataAdapter. Update (DataSet) is enough.

Http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/3abaaa25-7b73-47f0-af37-01c89698028e

The AcceptChanges method saves all changes to DataSet or able, so that all rows are inUnchanged(Not changed)

And DataAdapter. the Update method performs a check when saving data to the database table, that is, checks whether the table row has been modified. If the table row has not been modified, the Update method does not execute any commands and directly skips the row, check the next row. In this way, if the row of a table is in the Unchanged state, it will not be updated to the database.

Therefore, after changing the DataSet or able, if you want to call the DataAdapter. Update method to directly Update data to the database, you only need this Update method. You do not need to call the AcceptChanges method once before.

 

Modify: This article summarizes the add, delete, and update operations to modify

 

After thinking for three hours in the afternoon, I had no clue why I had never known why I had to call the Save method after accepting the changes, so I could not save the data to the database.

In the evening, I went to my colleagues' house to eat dumplings. I had 23 dumplings and chatted for a few days. It was time to go home at. It was another two or three minutes away from home, I suddenly posted this post in my head. It's strange that we haven't discussed the technology in the past few hours. I have come up with some ideas, as a result, when I was about to open the door with a key, Haha, I figured it out, and I came back to check it. net source code, it is indeed like this, the first save changed the row status, resulting in the second check no rows need to be saved.

It's so strange that I haven't posted any post in the past few hours. I haven't discussed the technology, so I suddenly came up with a new idea and understood it in 2 or 3 minutes. Now let's think about it. Alas, I don't have to work for three hours in the afternoon. How nice it is to eat dumplings first, maybe it won't be so long.

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.