I thought about using sqlcommandbuilder for batch update in one day. I have some new ideas.

Source: Internet
Author: User

In the past, data management usually avoided batch update. The reason is very simple. Because the browser has no mode, the system overhead is very high to save its status, andProgramIt will also become complicated.

However, in actual project development, it is often necessary to face this challenge. Many users prefer to modify a table or document, save (submit) all the work ). That is to say, batch update should bring a better user experience. Today, I took a day to figure out batch update. Although the progress is not great, I still have some new ideas. I will record them here.

Although many developers are worried about the performance of the gridview, I still like to use this control. After all, the function is too powerful. The data to be updated is first bound to a gridview for display. For the content to be changed, the template column is used for binding, and a text box is placed in the middle of the column. If you want to delete a row or add a row, I first save the original data on the grid to a able. Of course, the structure of this datatable is consistent with that of the table in the database. Then, the data to be deleted or added is processed (deleted or added) in the datatable ). Finally, rebind the datatable to the gridview. When batch updating, I delete all the original data from the database table, traverse the rows in the gridview, and re-write the data to the table in turn.

This method is relatively easy to control. The main problem is that it is too stupid to rewrite all records during update regardless of November 21 and November 21. In addition, you have also marked the changed records. During the update, you can determine the records based on the tags to perform different operations, but it is always too troublesome.

In fact, I also know that ado.net provides an automatic update method, but I am always afraid that I have never used it. In fact, it is not very complicated. Create a sqlcommandbuilder object, specify its adapter object (sqldataadapter), and use the update method of the adapter (sqldataadapter) to update the corresponding dataset. The key to use is the DataSet object. First, you need to obtain the DataSet object to be updated. The next step is to process the dataset (delete, update, and add). If you want to update the dataset, you can focus on deletion and addition, because they need to change the number of datasets, and each processing will do a lot of data cache work because of the saved status. After one day, I did not find a simple and perfect solution. I always felt that the processing process was complicated and it would consume a lot of resources during rollback.

I always thought there would be a simple method, but I could not find it at the moment. I will use it in the project tomorrow to see if I can make any changes.

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.