Dataset and datatable

Source: Internet
Author: User

Dataset and datatable

Each dataset is a collection of one or more able objects (datatable is equivalent to a table in the database). These objects are composed of datarow, datacolumn, and columnname) item, and the relationship (Relations) related to the data in the datatable object and the data display sorting (dataview) information.

Difference between dataset and datatable

Dataset: Dataset. It generally contains multiple able. When used, dataset ["table name"] obtains the datatable: data table.

I:

Sqldataadapter da = new sqldataadapter (CMD );

Datatable dt = new datatable (); da. Fill (DT );

----------------- Put the data result directly into the able,

II:

Sqldataadapter da = new sqldataadapter (CMD );

Dataset dt = new dataset ();

Da. Fill (DT );

------ The data result is put into dataset. If you want to use the datatable, you can do this: DataSet [0] more common usage:

Sqldataadapter da = new sqldataadapter (CMD );

Dataset dt = new dataset ();

Da. Fill (DT, "Table1 ");

In this way, the datatable: DataSet ["Table1"] specific application is obtained:

Sqlconnection con = new sqlconnection ("Server =.; database = chargesystem; uid = sa; Pwd = 123 ;");

Sqldataadapter SDA = new sqldataadapter ("select * from student", con );

Dataset DS = new dataset ();

SDA. Fill (DS, "stutable ");

This. gridview1.datasource = Ds. Tables ["stutable"];

This. gridview1.databind ();

DS. Dispose ();

Con. Close ();

Con. Dispose ();

 

Datatable
And
Dataset Value

1.
Take the value of the first column of the First row (Dt. Rows [0] [0]. tostirng ())

Dataset DS = new dataset ();

DS. Tables [0]. Rows [0] [0]. tostring ();

 

2. Field name of the corresponding column in the first row (Dt. Rows. Count DT. Columns. Count)

DS. Tables [0]. Rows [0] ["field name"]. tostring ();

Dbset. Tables (0). Rows (0). Item ("first column name ")

 

3.
Total number of rows and columns

Dataset_x.tables ["tablename"]. Rows. Count

Dataset_y.tables ["tablename"]. Columns. Count

4.
Obtains the value of a column.

Dataset. Tables ["personinfo"]. Rows [0] ["Age"]. tostring ();

 

5. Insert a new column into Dataset

Dataset DS = new dataset ();

DS. Table [0]. Columns. Add ("field name", "field type ");

6.
Add a record to Dataset

Datasetds = new dataset ();

Datarowdr = Ds. Tables [0]. newrow ();

Dr ["finishdate"] = finishdate;

Dr ["operator"] = operator;

Dr ["disp"] = disp;

DS. Tables [0]. Rows. Add (DR );

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.