A DataTable represents a data table in memory, not a table in a database. Any changes to the DataTable will not affect the database until it is persisted to the database.
The DataAdapter.Update method can be used to persist to a database.
The DataTable objects include:
1. Multiple DataColumn objects
2. Multiple DataRow objects.
To create a DataTable object first
DataTable table1=new DataTable ();
To add a Column object to a DataTable object
DataColumn Coluserid = new DataColumn ("user_id", Type.GetType ("System.int"));
Table1. Columns.Add (colcurrency);
The system type name of the column: Because the DataTable is an in-memory table and not a table in the database, its DataColumn data type is the system data type. Can be obtained in the following two ways:
typeof (System type name) settings such as:
DataColumn C1 = new DataColumn ("id", typeof (int));
Type.GetType ("System. Type name") setting
DataColumn C2 = new DataColumn ("name", Type. GetType ("System.String"));
DataColumn DC2 = new DataColumn ();
DC2. AllowDBNull = false; NULL is not allowed
DC2. MaxLength = 10; The maximum length is 10
DC2. Unique = true; Name column does not repeat
Table1. PrimaryKey = new datacolumn[] {DC1};//setting primary key is ID
datarow[] rows = table1. Select ("id>=1000 and name Like '");//Find
Table1. AcceptChanges (); Take Back Roll
Response.Write (table1. Rows[0]. Rowstate.tostring ());
Table1. rows[0]["Name" = "Leslie"; Write-Modify statements between AcceptChanges () and RejectChanges ()
Response.Write (table1. Rows[0]. Rowstate.tostring ());
Table1. RejectChanges (); Rolling back
Table1. rows[1]["Name" = "Guan Yu";//Modify
Table1. ROWS[2]. Delete (); Delete, delete only state do not delete data
Table1. Rows.removeat (2); Delete, delete completely