Differences between DataSet, able, and DataRow

Source: Internet
Author: User

DataSet
Indicates the data cache in the memory.

Attribute
Tables obtains the set of Tables contained in DataSet.

Ds. Tables ["sjxx"]

 

DataTable

Indicates a table of data in the memory.

Public attributes
Columns obtains the set of Columns that belong to the table.

DataSet obtains the DataSet to which the table belongs.

DefaultView: obtains the custom view of a table that may contain a filtering view or a cursor position.

PrimaryKey obtains or sets an array of columns that act as the primary key of the data table.

Rows obtains the set of Rows belonging to the table.

TableName: Get or set the name of the DataTable.

 

DataRow

Indicates a row of data in the DataTable.

Row ["index"]

 

DataColumn

The structure of columns in the able.


Copy codeThe Code is as follows:
Examples of common DataTable and DataSet operations

// Create a DataSet
DataSet ds = new DataSet ();

// Create a able
DataTable dt = new DataTable ();
Dt. Columns. Add ("id", Type. GetType ("System. Int32 "));
Dt. Columns ["id"]. AutoIncrement = true;
Dt. Columns. Add ("name", Type. GetType ("System. String "));

// Insert rows
DataRow dw1 = dt. NewRow ();
Dw1 ["name"] = "test1 ";
Dt. Rows. Add (dw1 );

DataRow dw2 = dt. NewRow ();
Dw2 ["name"] = "test2 ";
Dt. Rows. InsertAt (dw2, 0 );

// Add the DataTable to the DataSet
Ds. Tables. Add (dt );

// DataTable Query
DataTable dt = new DataTable ();
DataRow dr [] = dt. Select ("1 = 1 ");

// DataTable update
DataTable dt = (DataTable) HttpContext. Current. Cache ["MYCACHE"];
DataRow [] dr = dt. Select ("1 = 1 ");
If (dr. Length> 0)
{
Dr [0] ["colName"] = "colValue ";
}

// Statistics
Object o = dt. Compute ("SUM (col_name)", "1 = 1 ");

Related Article

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.