1. Create a DataTable
DataTable dt=new datable ();//
You can create a name for the table, TB
2. Add a column name to the table:
Dt. Columns.Add ("id",
typeof (System.Int32));//
Types can be transformed, such as
System.int32,system.double.
Dt. Columns.Add ("type", typeof (System.String));
3. Add lines to the table, content:
DataRow Row=dt. NewRow ();
row["id"]=1;
row["type"]= "123";
Dt. Rows.Add (row);//
This allows you to add a
Row=dt. NewRow ();
row["id"]=2;
row["type"]= "456";
Dt. Rows.Add (row);
4. Filter the contents of the table, and look for information with ID 1
DataRow []arr=dt. Select ("id=1");//
The return is an array
5. Insert the filtered content into another table
DataTable Dtnew=dt. Clone ();//
Copy the column information in the table dt dtnew, not copy the data.
foreach (DataRow row in arr)
{
Dtnew. Rows.Add (row);//
The filtered information is added to the
Dtnew
In
}
Dt. AcceptChanges ();//
After you add it, remember to refresh it.
!
6. Sorting tables
Dt. Defaultview.sort = "id desc";
7. Delete Data
Dt. Rows.remove (row);//
Under
Row
The line information is removed from DT. Rows.removeat (index);//
Delete based on index indexes
8. Modify the DT column information
Row2[0]. BeginEdit ();
row2[0]["status"] = 0;
Row2[0]. EndEdit ();
C # Operations DataTable