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 ();