Non-link access to the database-the queried Dataset is stored in Dataset ., Connection Mode dataset

Source: Internet
Author: User

Non-link access to the database-the queried Dataset is stored in Dataset ., Connection Mode dataset

Private void Button_Click_1 (object sender, RoutedEventArgs e) {// access the database in non-link mode, // 1 create a connection object (connection string) using (SqlConnection conn = new SqlConnection (SQLHelper. connectionString) {// 2. create data adapter object using (SqlDataAdapter sda = new SqlDataAdapter ("select * from Student", conn) {// 3. open the database connection (this step can be omitted) conn. open (); DataSet ds = new DataSet (); // 4. send command sda. fill (ds); // 5. close the connection // Note: Because the using code block is used here, closing the connection can save DataRowCollection drCollection = ds. tables [0]. rows; for (int I = 0; I <drCollection. count; I ++) {DataRow dr = drCollection [I]; MessageBox. show (dr ["s_Name"]. toString ());}}}}

Note: dataset occupies the memory. We can query the memory size of your data.

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.