Front-End Interface operation datatable data table 2

Source: Internet
Author: User
Tags dot net

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.