ADO.NET in-depth study (1) [Special recommendation]

zhaozj2021-02-08  203

Guide: .NET has made great adjustments in data access. Under the .NET framework, data access is done by ADO.NET, which is an improvement and perfect version of ADO. Its most significant change is its complete XML based entirely. For those who engage in ADO development, the disappearance of the Recordset object has also surprised them.

Translation: .NET Technology Network (www.51dot.com) Slash Original Source: http://www.dnjonline.com/articles/essentials/iss22_essentials.html .NET has made great adjustments in data access. Under the .NET framework, data access is done by ADO.NET, which is an improvement and perfect version of ADO. Its most significant change is its complete XML based entirely. For those who engage in ADO development, the disappearance of the Recordset object has also surprised them. Microsoft's view to Recordset objects is that it is too bloated relative to the initial mechanism to produce a SQL query. Therefore, in ADO.NET, the function of the Recordset object will be split into three parts. The first is the DataReader object, the function it wants to complete is to express the data simply; in ADO, the similar function is implemented by the forward, server-only cursor (the Server-Side Cursor). This is then DataSet and DataSetCommand objects that can create a cache for one or more data sets at the client and operate them. In ADO, the use of client cursors is relatively monolithized, and ADO.NET is given to the two objects, respectively, making them more specific and powerful. Finally, there are some functions that can be implemented in the ADO, such as, using the Connection object to update data in conservative locking. This is a function that cannot be implemented in ADO.NET, which means that at some point, ADO will continue to use. Before entering the discussion of DataSet, let's take a look at ADO.NET. Three classes were available from DataReader ADO.NET: DBConnection, DBCommand and DBDataReader, which are similar to traditional ADO objects. But they cannot be used directly in the .NET application. Can be used, such as Adoconnection, Adocommand, and AdodataReader to read data, the premise here is an OLEDB's Provider. If the object to be operated is SQL Server, you will use the same class SQLCONNECTION, SQLCOMMAND, and SQLDATAREADER using others to achieve better operating performance directly through the SQL Server TDS connection channel.

Here is an example (because the code difference between C # and VB.NET here is not very large, so only VB.NET instance): imports system.dataimports system.data.ado..dim cn as new adoconnection () CN .Connectionstring = strconnecttry cn () DIM CD AS NEW Adocommand (搒 ELECT * AUTHORS? CN) DIM DR AS ADODATAREADER CD.EXECUTE (DR) While Dr.Read () listbox1.items.add (DR (揳 u_lname? ) End Whilecatch Err as Exception MsgBox (Err.ToString) Finally if cn.State = DBObjectState.Open1 cn.close () End Try You will find that there is no MoveNext method in the While loop statement, because DataReader's Read method Automatic front movement is returned to return a false value when there is no data. This obviously reduces the developer's workload. In both cases, DataReader is recommended: 1. The customer interface uses handwritten code, or useless To data binding and data update is a handwritten SQL statement or a stored procedure, DataReader will provide a method of accessing related data; For example, automatic update features. Some of the better application instances are fill the data, and the product number is verified. Understand that DataSets can be used for some developers, but in fact, master it It is not difficult. If you are disconnected by the Recordset mode, as well as the use of the hierarchical Recordset, and if you use some XML, then use DataseTs, there is nothing difficult. But if you need to spend time to re-learn One object model? One of the reasons is that the disconnected model of the ADO.NET force is very meaningful. Disconnected data is higher, because this mode is the pressure of the data server It is relatively small. The intermediate layer is expanded over the parallel server. The extension is easier, so the use of the scalable application, the use of the data layer resources should be cautious. Disconnecting mode will be applied here. Reason 2, in terms of data management, disconnecting mode has a very broad prospect. If there is a technology development than ADO, this is XML. XML solves the limitations of two ADOs. 1, XML is more applicable to cross-platform data transmission because it can pass through the firewall. 2, XML is more than the type of expansion ADO2.5 described than ADO. A simple example is the same as flat data, and ordinary XML will show higher efficiency than ADO. DataSet is a combination of XML and ADO. An important feature is independent of database or SQL. It is just simple to operate, exchange data, or bind data to the user interface. There are two ways to add data sheets to DataSets: 1. Use the DataSetCommand object, which can return a result of a database query in XML. When processing a database update, this method is basically the same as the client cursor of ADO, but provides stronger control. 2. Operate the XML data directly.

The DataSet object has a method of reading and writing XML data and Schemas, and can work closely with the XMLDATADOCUMENT object (which is the inheritance of the multi-purpose XMLDocument class), which has some special functions for flat data operations therefore Bridge from Dataset to General XML DOM. Here is a paragraph code: DIM DC AS New AdodatasetCommand (_ "SELECT AU_ID, AU_FNAME, AU_LNAME AUTHORS" & _ "Where au_lname = 'ringer'", strconnect) DIM DS AS NEW DATASET () DC.FILLDataSet (DS) , "Authors") MsgBox (DS.XMLSCHEMA,, "XML Schema") MsgBox (DS.XMLDATA, "XML Data") The above code is filled with a 'authors' data table into the DataSet object instance DS, and displays XML data and Schemas, see two display results: Table 1 and Table 2 are very easy to add data tables to DataSet, please see the following code: DC = New AdodatasetCommand (_ "Select * from titleauthor" & _ "WHERE TITLE_ID LIKE 'PS%'", STRCONNECT DC.FILLDATASET (DS, "Titles") MSGBox (DS.XMLDATA, "XML DATA" Table 1 Display XML Schema Table 2 Shows the data generated by the DataSet object Guide: .NET has made great adjustments in data access. Under the .NET framework, data access is done by ADO.NET, which is an improvement and perfect version of ADO. Its most significant change is its complete XML based entirely. For those who engage in ADO development, the disappearance of the Recordset object has also surprised them.

Translation: .NET Technology Network (www.51dot.com) Slash Original Source: http://www.dnjonline.com/articles/essentials/iss22_essentials.html .NET has made great adjustments in data access. Under the .NET framework, data access is done by ADO.NET, which is an improvement and perfect version of ADO. Its most significant change is its complete XML based entirely. For those who engage in ADO development, the disappearance of the Recordset object has also surprised them. Microsoft's view to Recordset objects is that it is too bloated relative to the initial mechanism to produce a SQL query. Therefore, in ADO.NET, the function of the Recordset object will be split into three parts. The first is the DataReader object, the function it wants to complete is to express the data simply; in ADO, the similar function is implemented by the forward, server-only cursor (the Server-Side Cursor). This is then DataSet and DataSetCommand objects that can create a cache for one or more data sets at the client and operate them. In ADO, the use of client cursors is relatively monolithized, and ADO.NET is given to the two objects, respectively, making them more specific and powerful. Finally, there are some functions that can be implemented in the ADO, such as, using the Connection object to update data in conservative locking. This is a function that cannot be implemented in ADO.NET, which means that at some point, ADO will continue to use. Before entering the discussion of DataSet, let's take a look at ADO.NET. Three classes were available from DataReader ADO.NET: DBConnection, DBCommand and DBDataReader, which are similar to traditional ADO objects. But they cannot be used directly in the .NET application. Can be used, such as Adoconnection, Adocommand, and AdodataReader to read data, the premise here is an OLEDB's Provider. If the object to be operated is SQL Server, you will use the same class SQLCONNECTION, SQLCOMMAND, and SQLDATAREADER using others to achieve better operating performance directly through the SQL Server TDS connection channel.

Here is an example (because the code difference between C # and VB.NET here is not very large, so only VB.NET instance): imports system.dataimports system.data.ado..dim cn as new adoconnection () CN .Connectionstring = strconnecttry cn () DIM CD AS NEW Adocommand (搒 ELECT * AUTHORS? CN) DIM DR AS ADODATAREADER CD.EXECUTE (DR) While Dr.Read () listbox1.items.add (DR (揳 u_lname? ) End Whilecatch Err as Exception MsgBox (Err.ToString) Finally if cn.State = DBObjectState.Open1 cn.close () End Try You will find that there is no MoveNext method in the While loop statement, because DataReader's Read method Automatic front movement is returned to return a false value when there is no data. This obviously reduces the developer's workload. In both cases, DataReader is recommended: 1. The customer interface uses handwritten code, or useless To data binding and data update is a handwritten SQL statement or a stored procedure, DataReader will provide a method of accessing related data; For example, automatic update features. Some of the better application instances are fill the data, and the product number is verified. Understand that DataSets can be used for some developers, but in fact, master it It is not difficult. If you are disconnected by the Recordset mode, as well as the use of the hierarchical Recordset, and if you use some XML, then use DataseTs, there is nothing difficult. But if you need to spend time to re-learn One object model? One of the reasons is that the disconnected model of the ADO.NET force is very meaningful. Disconnected data is higher, because this mode is the pressure of the data server It is relatively small. The intermediate layer is expanded over the parallel server. The extension is easier, so the use of the scalable application, the use of the data layer resources should be cautious. Disconnecting mode will be applied here. Reason 2, in terms of data management, disconnecting mode has a very broad prospect. If there is a technology development than ADO, this is XML. XML solves the limitations of two ADOs. 1, XML is more applicable to cross-platform data transmission because it can pass through the firewall. 2, XML is more than the type of expansion ADO2.5 described than ADO. A simple example is the same as flat data, and ordinary XML will show higher efficiency than ADO. DataSet is a combination of XML and ADO. An important feature is independent of database or SQL. It is just simple to operate, exchange data, or bind data to the user interface. There are two ways to add data sheets to DataSets: 1. Use the DataSetCommand object, which can return a result of a database query in XML. When processing a database update, this method is basically the same as the client cursor of ADO, but provides stronger control. 2. Operate the XML data directly.

转载请注明原文地址:https://www.9cbs.com/read-3226.html

New Post(0)