C # DataSet and DataTable detailed

Source: Internet
Author: User

1. Create a DataSet object:

DataSet ds = new DataSet ("DatasetName");

2. View the structure created by calling Sqldataadapter.fill

Da. Fill (ds, "Orders");

DataTable tbl = ds. TABLE[0];

foreach (DataColumn col in tbl. Columns)

Console.WriteLine (Col. ColumnName);

3, view the data returned by SqlDataAdapter

①, DataRow objects

DataTable tbl = ds. TABLE[0];

DataRow row = tbl. ROW[0];

Console.WriteLine (ros["OrderID"]);

②, checking the data stored in DataRow

DataTable tbl = row. Table;

foreach (DataColumn col in tbl. Columns)

Console.WriteLine (Row[col]);

③, checking for DataRow objects in dattable

foreach (DataRow row in tbl. Rows)

DisplayRow (row);

4, verify the data in the dataset

①, validating DataColumn properties: Readonly,allowdbnull,maxlength,unique

Constrains collection of ②, DataTable objects: Uiqueconstraints,primarykey,foreignkeyconstraints

It is not usually necessary to create a foreignkeyconstraints, because one is created when a relationship is created between the two DataTable objects in the dataset.

③, using Sqldataadapter.fill mode to retrieve schema information

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.