On the DataSet object in ASP.

Source: Internet
Author: User

When we operate on the database, we always take the data out of the database, then put it in a "container", and then the data from the "container" is displayed in the foreground, and the role of this container is a dataset is the most common and important, It can be said that datasets play a role in the database and the foreground.

Let's talk about the use of datasets. (TheDataSet object itself is not the ability to access the database, it should be used in conjunction with DataAdapter, and about the use of DataAdapter in my other article is introduced, you can look at)

A dataset can contain multiple data tables that can be dynamically generated in a program, and the data tables here can come from a database, a file, or an XML (which has already been used in XML, not very well-understood words to look at). The dataset provides a way to browse, edit, sort, filter, and create views of the data.

The dataset accesses the database in a non-connected transport mode, that is, when the data requested by the user is read into the dataset, the link to the database is closed so that other users can continue to use the data source.

As I've been using the dataset for so long, not only does it use fixed statements about datasets, I actually realize that the structure of the dataset is the most critical. Here is the structure of the DataSet object:


Properties and methods of the DataSet object:

DatasetName Gets or sets the name of the DataSet object

Tables

Gets the dataset's data table collection (DataTableCollection), whichis owned by all DataTable objects of the DataSet object DataTableCollection

The most commonly used property is tables, which allows you to get or set the value of a data table row, column.

For example, an expression of "DS." tables["ShoppingCart"].rows (i). Item (j) "means access to the ShoppingCart table in column I, section J.

The most common methods are clear () and copy (). The clear method is to clear the DataSet object's data and delete all DataTable objects. The Copy method copies the structure and data of the DataSet object, which is a dataset object that has the same structure and data as this DataSet object .

Simple example: (no foreground code, only the background with the dataset related parts of the code, but then I will upload this case, we are interested to see)

[CSharp]View Plaincopyprint?
    1. protected void Page_Load (object Sender,eventargs e)
    2. {
    3. The SqlConnection of the linked database is temporarily omitted first
    4. SqlDataAdapter sqlad = new SqlDataAdapter (Sql,con); //Create SqlDataAdapter object and execute SQL query
    5. DataSet ds = new dataset (); //Create Data set
    6. Sqlad.  Fill (DS); //Fill data set
    7. Gridview1.datasource=ds. Tables[0].  DefaultView; //Set data source
    8. Gridview1.databind (); //Bind data source
    9. }

On the DataSet object in ASP.

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.