I. Datasets, DataTable, DataRow, DataColumn
1 "Adding a DataTable to a dataset
DATASET.TABLES.ADD (DataTable)
Instance:
DataSet ds=new DataSet ();
DataTable table=new DataTable ("Student Table");
Ds. Tables.add (table);
2 "Reading a DataTable from a dataset
Datatable=dataset.tables[0] or dataset.tables["table name"]
Instance:
DataTable Table=ds[i] or DataTable table=ds["Student Table"]
I is the index value in the dataset because the dataset can hold multiple DataTable, you can find a DataTable based on the index value, or write the name of the DataTable directly to find a DataTable
3 "Add row
DataTable t=new DataTable ();
DataRow R=t.newrow ();
r["column name"]= column value;
T.rows.add (R);
Instance:
DataTable: Student Table
ID Name
1 Xun
Code:
DataTable t=new DataTable ("Student Table");
DataRow R=t.newrow ();
r["id"]=2;
r["Name"]=XUN2;
T.rows.add (R);
4 "Add column
DATATABLE.COLUMNS.ADD ("Column name", Type.GetType ("Data type"));
5 "Reading column values from rows
datarow["column name"] or Datarow[datacolumn];
6 "Reading column values from a DataTable
DataTable table;
A, table. rows[i]["column name"]
b, table. Rows[i][i]
C, table[i]. Column names (column names are not quoted)
7 "read out a specific line
DataTable table;
Datarow[] selectrow=table. Select ("Column name = '" + holds a specific variable.) ToString () + "'");
Select one of the rows: selectrow[index]
Ii. Delete rows in a DataTable three methods: (DataTable.Rows.Remove (DataRow Dr), DataTable.Rows.RemoveAt (i), Datarow.delete ())
Delete Rows in a DataTable to be aware of indexing problems, there are generally two methods:
1 "With A For loop, note that the counter initial value is the table length, the self-decrement loop. DataTable.Rows.RemoveAt (i) should be noted.
2 "With the Select method of the DataTable, note that the parameter of the method is a string filter
A DataTable is required after 3 "Delete (). The Acceptechanges () method confirms a complete deletion, because delete () only flags the status of the corresponding column as deleted, and it can be passed through a DataTable. RejectChanges () rollback to make the row undelete. To delete multiple rows, you can use Delete () consecutively, and then use the Acceptechanges () method to confirm the deletion.
C#datatable learning experience [turn]