DataTable common sense [. NET Framework 2.0]

Source: Internet
Author: User

When DataTable is used today, some common knowledge in DataTable is recorded for future reference.
For this reason, I wrote a very easy example. The example is prepared for our rookie.
I would like to give more advice on the shortcomings in the examples,
Includes:
1: Create a able
2: How to Use
3: How to Use foreach

Static void Main (string [] args)
{
DataTable dt = InitialData ();

// Find the column whose value is greater than A_3 in able
DataRow [] drs = dt. Select ("A> 'A _ 3'", "A desc ");

Console. WriteLine ("A \ tB \ tC \ tD ");

// Traverse data
Foreach (DataRow row in drs)
{
String a = row ["A"] as string;
String B = row ["B"] as string;
String c = row ["C"] as string;
String d = row ["D"] as string;
Console. WriteLine (a + "\ t" + B + "\ t" + c + "\ t" + d );
}

Console. ReadKey ();
}

/// <Summary>
/// Initialize Test Data
/// </Summary>
Public static DataTable InitialData ()
{
// Create a data table named TestTable
DataTable dt = new DataTable ("TestTable ");

// Create four columns for the table: A, B, C, and D
Dt. Columns. Add (new DataColumn (""));
Dt. Columns. Add (new DataColumn ("B "));
Dt. Columns. Add (new DataColumn ("C "));
Dt. Columns. Add (new DataColumn ("D "));

For (int I = 1; I <= 10; I ++)
{
// Add a new data row and add data
DataRow dr = dt. NewRow ();
Dr ["A"] = "A _" + I;
Dr ["B"] = "B _" + I;
Dr ["C"] = "C _" + I;
Dr ["D"] = "D _" + I;

// Add this row to the able
Dt. Rows. Add (dr );
}

Return dt;
}

Author: "The Soul of Wolf"

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.