DataSet
Indicates the data cache in the memory.
Attribute
Tables obtains the set of Tables contained in DataSet.
Ds. Tables ["sjxx"]
DataTable
Indicates a table of data in the memory.
Public attributes
Columns obtains the set of Columns that belong to the table.
DataSet obtains the DataSet to which the table belongs.
DefaultView: obtains the custom view of a table that may contain a filtering view or a cursor position.
PrimaryKey obtains or sets an array of columns that act as the primary key of the data table.
Rows obtains the set of Rows belonging to the table.
TableName: Get or set the name of the DataTable.
DataRow
Indicates a row of data in the DataTable.
Row ["index"]
DataColumn
The structure of columns in the able.
Copy codeThe Code is as follows:
Examples of common DataTable and DataSet operations
// Create a DataSet
DataSet ds = new DataSet ();
// Create a able
DataTable dt = new DataTable ();
Dt. Columns. Add ("id", Type. GetType ("System. Int32 "));
Dt. Columns ["id"]. AutoIncrement = true;
Dt. Columns. Add ("name", Type. GetType ("System. String "));
// Insert rows
DataRow dw1 = dt. NewRow ();
Dw1 ["name"] = "test1 ";
Dt. Rows. Add (dw1 );
DataRow dw2 = dt. NewRow ();
Dw2 ["name"] = "test2 ";
Dt. Rows. InsertAt (dw2, 0 );
// Add the DataTable to the DataSet
Ds. Tables. Add (dt );
// DataTable Query
DataTable dt = new DataTable ();
DataRow dr [] = dt. Select ("1 = 1 ");
// DataTable update
DataTable dt = (DataTable) HttpContext. Current. Cache ["MYCACHE"];
DataRow [] dr = dt. Select ("1 = 1 ");
If (dr. Length> 0)
{
Dr [0] ["colName"] = "colValue ";
}
// Statistics
Object o = dt. Compute ("SUM (col_name)", "1 = 1 ");