Dataset and datatable
Each dataset is a collection of one or more able objects (datatable is equivalent to a table in the database). These objects are composed of datarow, datacolumn, and columnname) item, and the relationship (Relations) related to the data in the datatable object and the data display sorting (dataview) information.
Difference between dataset and datatable
Dataset: Dataset. It generally contains multiple able. When used, dataset ["table name"] obtains the datatable: data table.
I:
Sqldataadapter da = new sqldataadapter (CMD );
Datatable dt = new datatable (); da. Fill (DT );
----------------- Put the data result directly into the able,
II:
Sqldataadapter da = new sqldataadapter (CMD );
Dataset dt = new dataset ();
Da. Fill (DT );
------ The data result is put into dataset. If you want to use the datatable, you can do this: DataSet [0] more common usage:
Sqldataadapter da = new sqldataadapter (CMD );
Dataset dt = new dataset ();
Da. Fill (DT, "Table1 ");
In this way, the datatable: DataSet ["Table1"] specific application is obtained:
Sqlconnection con = new sqlconnection ("Server =.; database = chargesystem; uid = sa; Pwd = 123 ;");
Sqldataadapter SDA = new sqldataadapter ("select * from student", con );
Dataset DS = new dataset ();
SDA. Fill (DS, "stutable ");
This. gridview1.datasource = Ds. Tables ["stutable"];
This. gridview1.databind ();
DS. Dispose ();
Con. Close ();
Con. Dispose ();
Datatable
And
Dataset Value
1.
Take the value of the first column of the First row (Dt. Rows [0] [0]. tostirng ())
Dataset DS = new dataset ();
DS. Tables [0]. Rows [0] [0]. tostring ();
2. Field name of the corresponding column in the first row (Dt. Rows. Count DT. Columns. Count)
DS. Tables [0]. Rows [0] ["field name"]. tostring ();
Dbset. Tables (0). Rows (0). Item ("first column name ")
3.
Total number of rows and columns
Dataset_x.tables ["tablename"]. Rows. Count
Dataset_y.tables ["tablename"]. Columns. Count
4.
Obtains the value of a column.
Dataset. Tables ["personinfo"]. Rows [0] ["Age"]. tostring ();
5. Insert a new column into Dataset
Dataset DS = new dataset ();
DS. Table [0]. Columns. Add ("field name", "field type ");
6.
Add a record to Dataset
Datasetds = new dataset ();
Datarowdr = Ds. Tables [0]. newrow ();
Dr ["finishdate"] = finishdate;
Dr ["operator"] = operator;
Dr ["disp"] = disp;
DS. Tables [0]. Rows. Add (DR );