Introduction to ADO. NET core objects and introduction to ado.net core objects

Source: Internet
Author: User

Introduction to ADO. NET core objects and introduction to ado.net core objects

ADO. NET is an object-oriented class library in. NET for interacting with data sources. It provides high-level interfaces for data access.

The ADO. NOT class library is in the System. Data namespace. Select the namespace based on the different databases we visit, System. Data. SqlClient.

The most important advantage of the ADO. NET class is that it allows the database to work in a disconnected manner.

ADO. NET mainly uses two core components to perform database operations: DataSet and. NET database providers. Dataset, in the Command Space: System. Data.

The former is the core component of the ADO. NET disconnected structure, and the latter is a component designed to directly access the database, perform fast inbound access, read-only access to data and other data processing.

Common ADO. NET objects:


Connection to the database

Command Execution object

DataReader data reader

DataAdapter data adapter

Expression of DateSet data in memory

 

SqlConnection conn = new SqlConnection (); // create a Connection database object

Conn. ConnectionString = "data sourse = ..; initalial catalog = MySchool; integrated security = true;" // connection string

 

SqlCommand cmd = new SqlCommand (); // create a Command Execution object

Cmd. CommandText = "SELECT * FROM dbo. Student"; // SQL statement

Cmd. Connection = conn; // bind the Connection

Cmd. CommandType = CommandType. Text; // ensure that the string is correctly interpreted.

 

Conn. Open (); // Open the connection

 

SqlDataReader reader = cmd. ExecuteReader (); // execute the command

While (reader. Read ())
{

Do something

}

Conn. Close (); // Close the connection

Reader. Close ();

 

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.