I. Knowledge POint Description
Datatable
Is a virtual grid table that temporarily saves data (a table that represents data in the memory .). Datatable is the core object in the ADO dot net Library. It can simply bind a database without code. In C #, you can use the gridview and dataset to connect to the database to read data tables.
Datatable indicates a table with in-memory relational data, which can be created and used independently or by other. NET Framework objects. The most common situation is that it is used as a member of dataset.
You can use the corresponding able constructor to create a datatable object. You can add it to the tables set of the able object by using the add method and add it to the dataset.
You can also create a able object by using the fill method or fillschema method of the dataadapter object in dataset, alternatively, you can use the readxml, readxmlschema, or inferxmlschema methods of dataset to create a schema from a predefined or inferred XML schema. Note that after adding a able as a member to a dataset tables set, it cannot be added to any other dataset table set.
Ii. Mind Map
Iii. Sample Code
1. Create a database connection to sqlconnection
Using (sqlconnection conn = new sqlconnection (dbhelper. connstring ))
2. Database Command
String sql1 = "select doctorno as doctor's number, doctorname as doctor's login name, doctordutytime as doctor's duty time from doctor ";
3. Open Database open ()
Conn. open ()
4. insert data into the able
DA = new sqldataadapter (SQL, Conn );
DS = new dataset ();
Da. Fill (DS );
Dgvduty. datasource = Ds. Tables [0];
5. Close database connection
Conn. Close ();
6. The detailed code is as follows:
{
Sqldataadapter da;
Dataset Ds;
String SQL = "select doctorno as Administrator number, doctorname as administrator login name, doctorpwd as administrator login password, doctordutytime as doctor duty time from doctor order by doctorno DESC ";
Using (sqlconnection conn = new sqlconnection (dbhelper. connstring ))
{
DA = new sqldataadapter (SQL, Conn );
DS = new dataset ();
Da. Fill (DS );
Dgv_docdetail.datasource = Ds. Tables [0];
}
}
Iv. Effect
Front-End Interface operation datatable data table 2