Turn: Datasets, DataTable, DataRow, DataColumn differences and usage examples

Source: Internet
Author: User

DataSet

Represents the cache of data in memory.

Property
Tables gets the collection of tables contained in the DataSet.

Ds. tables["SJXX"]

DataTable

Represents a table of in-memory data.

Public properties
Columns gets the collection of columns that belong to the table.

The dataset gets the dataset to which this table belongs.

DefaultView gets a custom view of a table that might include a filtered view or cursor position.

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

Rows gets the collection of rows that belong to the table.

TableName Gets or sets the name of the DataTable.

DataRow

Represents a row of data in a DataTable

row["Index"]

DataColumn

Represents the schema for a column in a DataTable.

Examples of common operations for DataTable and dataset

Create a DataSet
DataSet ds = new DataSet ();

Create a DataTable
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 Row
DataRow dw1 = dt. NewRow ();
dw1["name"] = "test1";
Dt. Rows.Add (DW1);

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

Add a DataTable to a dataset
Ds. Tables.add (DT);

Query in DataTable
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");

(Transferred from Saysay,looklook, detections)

Goto: DataSet, DataTable, DataRow, DataColumn differences and usages

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.