DataAdapter Object fills a dataset

Source: Internet
Author: User

How to use the data adapter SqlDataAdapter to retrieve data from the database SQL Server and populate it with the dataset:

Methods to get data sets

Private DataSet GetDataSet ()
{
String Strcon = @ "Data source=./sqlexpress;initial catalog=school;uie=sa;pwd=123456";
SqlConnection con = new SqlConnection (Strcon);
String sql = "SELECT * from student";
DataSet ds = new DataSet ();
SqlDataAdapter objadpter = new SqlDataAdapter (sql, con);
Objadapter. Fill (ds, "Student");
return DS;
}

As you can see from the code, using an adapter to populate a dataset is divided into 4 steps:

Create a data connection (Connection) object.

Create an SQL statement to query the data in the database.

Third, create the DataAdapter object, the parameter is the SQL statement and the connection object.

Four, call the DataAdapter object's fill () method to fill the dataset

Note: When populating a DataSet with the Fill () method of the DataAdapter object, a datasheet is created if the dataset originally had no data tables. If you have a datasheet with the same name in the dataset, the data is added to the datasheet.

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.