ADO. NET
Consumer objects
Dataset: data is stored in memory. DataSet is a Dataset, including
DataTable and DataRelation, and DataTable contains DataRow and DataColumn. After the data is read to DataSet, you can perform CRUD operations on the DataTable as an index or table name.
. NET
Data Provider objects
Connection: database Connection object.
Purpose: 1. Connect to the database; 2. Create a Command object.
For example:
SqlConnection thisConnection = new SqlConnection (@ "server =. \ sqlexpress; Integrated Security =
True; Database = C: \ SQL SERVER 2000 SAMPLE DATABASES \ NORTHWND. MDF ");
ThisConnection. Open ();
SqlCommand thisCommand =
ThisConnection. CreateCommand ();
Command: database Command object. The Command type can be an SQL statement or a stored procedure.
For example:
ThisCommand. CommandType = CommandType. StoredProcedure;
ThisCommand. CommandText = "Ten
Most Expensive Products ";
CommandBuilder: used to build SQL commands. It is often used in combination with DataAdapter objects to automatically generate SQL statements.
For example:
SqlDataAdapter thisAdapter = new
SqlDataAdapter ("select
CustomerID from Customers ", thisConnection );
SqlCommandBuilder thisBuilder = new SqlCommandBuilder (thisAdapter );
You can obtain the CRUD method automatically generated in the CommandBuilder object.
DataReader: used to read only forward and read-only data. This object has the best performance for simple data reading.
For example:
SqlCommand thisCommand =
ThisConnection. CreateCommand ();
ThisCommand. CommandText = "select
CustomerID, CompanyName from Customers ";
SqlDataReader thisReader =
ThisCommand. ExecuteReader ();
DataAdapter: a bridge between the database and memory. It reads data from the database to Fill the DataSet object. The Fill () method is his.
DataSet thisDataSet = new
DataSet ();
SqlDataAdapter custAdapter = new
SqlDataAdapter ("select
* From MERs ", thisConnection );
CustAdapter. Fill (thisDataSet, "MERs ");
After the data is filled into the DataSet object, you can operate on one of the tables and perform CRUD operations on each row and column of a table.
ADO. NET and XML
You can write data from a DataSet object to an XML file:
For example:
DataSet thisDataSet = new
DataSet ();
OrderAdapter. Fill (thisDataSet, "Orders ");
ThisDataSet. WriteXml (@ "d: \ tmp \ nwinddata. xml ");
Of course, you can also read data from an XML file to a DataSet object:
For example:
DataSet thisDataSet = new
DataSet ();
ThisDataSet. ReadXml (@ "d: \ tmp \ nwinddata. xml ");