C # traversal DataSet and DataSet element implementation code

Source: Internet
Author: User
Tags foreach trim
The
  code is as follows copy code

//Multiple table Multiline multiple columns

foreach  (datatable dt in yourdataset.tables)  //traversal of all DataTable

foreach  (Datarow dr in dt. rows)  ///traverses all rows of
foreach  (DATACOLUMN DC IN DT). Columns)  //traverse all Columns
Console.WriteLine ("{0}, {1}, {2}",  dt.) TABLENAME,&NBSP

DC. COLUMNNAME, DR[DC]);  //table name, column name, cell data
}

//traverse a table Multiline multiple columns

foreach (datarow mdr in  dataset.tables[0]. rows )  

foreach (datacolumn mdc in dataset.tables[0). Columns)  

Console.WriteLine (MDR[MDC). ToString ());  

}


Traversing elements in a dataset

Paste a good code on the Web

The code is as follows Copy Code

DataSet2 ds = new DataSet2 ();
SqlDataAdapter da1 = new SqlDataAdapter (STR, conn);
da1. Fill (ds, "table");

Already loaded into dataset data set

for (int k = 0; k < ds. tables["Table"]. Rows.Count; k++)
{
for (int j = 0; J < ds.) tables["Table"]. Columns.count; J + +)
{


if (ds. tables["Table"]. rows[k]["Emergency"]. ToString (). Trim () = = "1")
{


Ds. tables["Table"]. rows[k]["emergency"] = "qualified";
}
else if (ds. tables["Table"]. rows[k]["Emergency"]. ToString (). Trim () = = "0")
{
Emergency = "disposal";
Ds. tables["Table"]. rows[k]["emergency"] = "disposal";


}
}
}
Ds. AcceptChanges ();

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.