Details of the differences between DataSet DataTable and DataRow
- 2020-11-26 18:45:12
- OfStack
DataSet
Represents the cache of data in memory.
attribute
Tables gets the collection of tables contained in DataSet.
ds.Tables["sjxx"]
DataTable
A table that represents data in memory.
Public attribute
Columns gets the collection of columns that belong to the table.
DataSet gets the DataSet to which this table belongs.
DefaultView gets a custom view that might include a table that filters views or cursor positions.
PrimaryKey gets or sets the array of columns that act as the primary key of the data table.
Rows gets the collection of rows that belong to the table.
TableName gets or sets the name of DataTable.
DataRow
Represents one row of data in DataTable
row["index"]
DataColumn
Represents the schema for the columns in DataTable.
DataTable with DataSet Common operation examples
// create DataSet
DataSet ds = new DataSet();
// create DataTable
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 row
DataRow dw1 = dt.NewRow();
dw1["name"] = "test1";
dt.Rows.Add(dw1);
DataRow dw2 = dt.NewRow();
dw2["name"] = "test2";
dt.Rows.InsertAt(dw2,0);
// will DataTable Added to the DataSet In the
ds.Tables.Add(dt);
//DataTable In the 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";
}
// statistical
object o = dt.Compute("SUM(col_name)", "1=1");