DataSet, DataAdapter, and ADO. netdataadapter In ado. NET

Source: Internet
Author: User

DataSet, DataAdapter, and ADO. netdataadapter In ado. NET
DataSet and DataTable

DataSet is a data set stored in the memory. It is a temporary database.

In my opinion, it is not very common. DataTable or directly store data with List <model> is better than this.

Let's talk about the usage.

 

DataSet ds = new DataSet ("school"); DataTable dt = new DataTable ("stu"); dt. columns. Add ("column name", typeof (string ));

 

// Note that DataRow dr = new DataRow (); cannot be used like this. Why? See the green text below

/*

The DataRow constructor is protected internal and you cannot call it.

However, the DataTable of the same assembly as DataRow can be called.

*/

DataRow dr = dt. NewRow (); dr ["column name"] = "xxx"; dt. Rows. Add (dr); ds. Tables. Add (dt );
DataAdapter

This class is an application in the adapter mode. So what exactly does this adapter adapt?

DataAdapter is applicable to the DataTable and DataReader return values.

 

String conn = ""; // connection string SQL = ""; // SQL statement/* DataAdapter is the encapsulation of Connection, Command, and DataReader */DataAdapter da = new DataAdapter (SQL, conn); DataTable dt = new DataTable (); /****** description ******* 1. constructing columns and filling columns will improve the efficiency. 2. Fill (, dt); is a paging method suitable for small projects. Go to one page and read all! */Da. Fill (0, 10, dt );
DataReader is recommended

1. A common way to obtain tables

// For short, DataSet ds = new DataSet (); DataAdapter da = new DataAdapter (SQL statement, connection string) da. fill (ds); // In fact, it is not recommended to obtain tables in this way. DataTable dt = ds. Tables [0];

2. Recommended Practices

// You can also abbreviated using (Connection conn = new Connection ("Connection string") {using (Command cmd = conn. createCommand () {using (DataReader reader = cmd. executeReader () {DataTable dt = new DataTable (); dt. load (reader );}}}
Under what circumstances is DataSet used?

1.InIn C/S Mode 

Use DataSet in C/S mode.

2.In B/S Mode 

Use DataSet in B/S mode. In B/S mode (ASP. NET), DataSet is used, with 1000 requests,

There will be 1000 DataSet in the memory of the Web server. Whether to use it or choose between them.

 

 

 

Related Article

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.