Five objects in ADO.NET

1. Five types of objects

1.Connection object:

The connection object is to open the connection between the database and the program. It is a connection object used to create a connection object. Without this object, information cannot be obtained from the database. It is at the bottom of ADO.NET.

2.Command object:

Issue commands to the database, create command objects, query the database, add, modify, and delete commands. The command object is created on the basis of the connection object and connects to the data source through the connection.

3. DataAdapter object:

It will be used to construct the adapter call result set, mainly to perform data transmission between the data source and the DataSet. After the command object issues a command, the obtained data is stored in the DataSet object.

4. DataSet object:

The DataSet object can save the information queried from the database, and even display the entire database. Get some data table structure such as primary key through DataSetCommand object, and can record the association between data tables. The DataSet object can be said to be a heavyweight object in ADO.NET. This object structure is based on the DataSetCommand object and does not have the ability to communicate with data sources; that is to say, we treat the DataSetCommand object as a DataSet object and transfer data between data sources. bridge.

5. DataReader object:

When we only need to read data sequentially without other operations, we can use the DataReader object. The DataReader object only reads the data in the data source sequentially one at a time, and these data are read-only, and other operations are not allowed.

Second use:

ADO.NET uses the Connection object to connect to the database, uses the Command or DataAdapter object to execute SQL statements, and returns the execution results to the DataReader or DataAdapter, and then uses the obtained DataReader or DataAdapter object to manipulate the data results.   

1.connection object:

Create connection object code: SQL: SqlConnection MyConnection = new SqlConnection();

Use the ConnectionString, ConnectionTimeout and mode properties to configure the connection before opening the connection for use;

Use ConnectionString to operate the configuration file, MyConnection.ConnectionString = "Data Source = (local); database = database name; uid = sa; pwd = "" ";

 

 

 

Guess you like

Origin blog.csdn.net/weixin_44682554/article/details/109337145