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 (); |