DataSetThe design of the ADO DataSet has made it clear that it can access data independent of any source of data. As a result, it can be used with different sources of data, used with XML data, or used to manage native data for applications. A DataSet contains one or more sets of DataTable objects consisting of columns and rows, and information about the primary key, external index key, condition constraint (Constraint), and data in a DataTable object. ADO provides a common method of interacting with the data source, but takes a different set of class libraries for different data sources. These class libraries are called data Providers and are typically named after the protocols and data source types that interact with them. ADO is. NET technology that interacts with the data source. There are many data Providers that will allow communication with different sources-depending on the protocol or database they are using. However, no matter what data Provider is used, the developer interacts with the data source using similar objects. The SqlConnection object manages the connection to the data source. The SqlCommand object allows the developer to communicate with the data source and send commands to it. In order to read the data quickly and only "forward", use SqlDataReader. If you want to use disconnected data, use a dataset and implement a SqlDataAdapter that reads or writes to the data source.
Connection classTo interact with the database, you must connect to it. The connection help indicates the database server, database name, user name, password, and other parameters required to connect to the database. The connection object is used by the command object to know which data source is executing the command. The process of interacting with a database means that you must indicate the action you want to perform. This is done by the Command object. The developer uses the command object to send the SQL statement to the database. The command object uses the connection object to indicate which data source to connect to. Developers can use the command object alone to execute commands directly, or to pass a reference to a Command object to DataAdapter, which holds a set of commands that manipulate the set of data described below.Command ObjectAfter the successful connection with the data, you can use the command object to execute query, modify, insert, delete and other commands; The common methods for command objects are the ExecuteReader () method, ExecuteScalar () method and ExecuteNonQuery () method; Insert data available ExecuteNonQuery () method to execute Insert commandDataReader classMany data operations require developers to simply read a string of data. The DataReader object allows the developer to obtain the results from the Command object's SELECT statement. Considering the performance factor, the data returned from DataReader is fast and is just a "forward" stream of data. This means that developers can only fetch data from the data stream in a certain order. This is good for speed, but if the developer needs to manipulate the data, a better approach is to use a dataset.DataSet ObjectA DataSet object is a representation of the data in memory. It includes multiple DataTable objects, while a DataTable contains columns and rows, just like a table in a normal database. Developers can even define relationships between tables to create a master-slave relationship (parent-child relationships). Datasets are used in specific scenarios-helping to manage the data in memory and supporting the disconnection of data. The dataset is an object used by all data providers, so it does not require a special prefix like data provider.DataAdapter ClassAt some point the data used by developers is primarily read-only, and developers rarely need to change it to the underlying data source. The same situation requires that data be cached in memory to reduce the number of times that unchanged data is called by the database. DataAdapter helps developers to easily handle the above situations by disconnecting the model. The DataAdapter fills the DataSet object when a continuous change in the read and write operation of a database is returned to the database in a single batch. The dataaadapter contains a reference to the Connection object and automatically opens or closes the connection when the database is read or written. In addition, DataAdapter contains a command object reference to the Select, INSERT, update, and delete operations of the data. The developer will define dataaadapter for each table in the dataset, which will take care of all connections to the database for the developer. So the job the developer will do is tell DataAdapter when to load or write to the databaseDataTable classA DataTable is a data grid control. It can be applied to VB and ASP. It can simply bind the database without code. It has a Microsoft-style user interface. Instantiation of a DataTable and adding columns: DataTable dt = new DataTable ();d T. Columns.Add ("ID");d T. Columns.Add ("Name");D Atarow dr = dt. NewRow (); object[] Objs = {1, "Name"};d R. ItemArray = Objs;dt. Rows.Add (dr); this.dataGridView1.DataSource = DT;
Content from Baidu Encyclopedia