Graphic demonstration of the working principle of ADO. Net Dataset

Source: Internet
Author: User

    I wantProgramEveryone knows the concept of dataset, but do you know the working principle and mechanism of ADO. Net dataset? I have collected a lot of information on the Internet and I have learned a little from my work. Let's take a look! For how the ADO. Net dataset works, see the figure below:


    the process shown in the figure is ADO. the working principle of the. NET dataset. First, the client establishes a connection with the database server. Then, the client application sends data requests to the database server. After receiving the data request, the database server retrieves and selects the data that meets the condition and sends the data to the client. In this case, the connection can be closed. Next, the dataset transmits data to the client application in the form of data binding controls or direct reference. If data changes during running of the client application, it modifies the data in the dataset. When an application is running at a certain stage, for example, if the application needs to save data, you can establish a connection from the client to the database server and submit the modified data in the dataset to the server, the connection is closed again.
    this operation does not require real-time database connection. When processing data in a DataSet object, the client application only uses data copies in the memory of the local machine. This relieves the pressure on the database server and network, because the database server can be connected only when the data is obtained for the first time, edited, and uploaded back to the database.

    Although this non-connection-oriented data structure has advantages, there are still problems. When the environment is disconnected, the client application does not know the changes made by other client applications to the original data in the database. It is possible to get outdated information.

    Case study: Create a DataSet object by encoding

    Create a new form named form5.cs. Double-click the form5 form interface to enter the background Encoding Area. In the form loading initialization event, type the followingCode:

    Code Private   Void Form5_load ( Object Sender, eventargs E)
    {
    // Create an SQL Server database connection
    String Connstring =   " Data Source = (local); initial catalog = school; user id = sa " ;
    Sqlconnection connection =   New Sqlconnection (connstring );
    Connection. open ();
    String Sqlstring =   " Select * from student " ;
    Sqlcommand mycom =   New Sqlcommand (sqlstring, connection );
    Sqldataadapter Adapter =   New Sqldataadapter ();
    Adapter. selectcommand = Mycom;
    // Create a DataSet object
    Dataset sqlds =   New Dataset ();
    Adapter. Fill (sqlds ); // Fill DataSet object with sqldataadapter object
    // Releases database connection resources. To develop a good programming habit, remember to clean up the garbage after operating the data!
    Connection. Dispose ();
    Connection. Close ();
    Connection =   Null ;
    }

     

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.