Ado.Net Getting Started (4)

zhaozj2021-02-16  62

4. Convert existing code

A large number of ASP pages use ADO objects to extract data. Let us review the typical cases of the next few cases, which may help when you process your transplant or override the code.

If you have an ASP page generated from a single Recordset, then DataReader will be your good helper.

String strconn, strcmd;

StrConn = "Database = myagenda; server = localhost; uid = sa; pwd =;";

Strcmd = "SELECT * from names where id =" contactid.text;

SqlConnection OCN = New SqlConnection (STRCONN);

SQLCommand OCMD = New SQLCOMMAND (STRCMD, OCN);

Ocn.open ();

SqlDataReader DR;

Ocmd.execute (OUT DR);

While (Dr.Read ()) {

// use Dr.getstring (Index) OR

// DR ["Field Name"] to response.write data

}

You can use the Hasmorerows property to quickly check if DataReader is empty. If you only handle a series of records, there is nothing than DataReader. Faster, better object, it applies to query a single record.

DataReader. The content is not editable, but you can move the content into a more manageable object, such as:

DataTable or one or more DATAROW objects.

DataReader is not a suitable tool when you need to handle the complex relationship between the table and the record. The more data model links, the more complicated the SQL command. The navigation module has continuity, and finally put into cache is more than what you need,. Dataset and DataRelation Objects are the basis of this form of relationship model.

To manage the Parent / Child relationship, ADO also packages Data-Shaping Engine. In general, Data Shaping and ADO .NET relationship is a matter. In terms of design, both have little common point. Shaped Recordsetsct All data sheet information is included in the embedded list object. ADO.NET relationship is dynamic link, you can build at any time in two datasheets. Ado relies on the Shaping Ole DB Service Provider and uses a dedicated SQL class language feature to generate a layering during the execution of a single ADO command. Recordset.

In ADO.NET, each object involved in the relationship is always seen as a separate individual. The relationship itself is disclosed as an object and has a certain behavioral rule. For example, the DataRelelation object can be changed from the father to the subline layer. You can do this by adding the ForeignKeyConstraint object to the CONSTRAINTS collection of the DataTable. The ForeignKeyConstraint object indicates a set of columns associated with the foreign key relationship when deleting or updating the values ​​and rows. As mentioned earlier, once the relationship is set, you cannot perform changes that may undermine the relationship before it is terminated by the program preset.

As mentioned earlier, once it sets RELATIONSHIP, unless it is a procedural termination, you cannot modify it, which will suddenly interrupt it.

In addition, Relations have no deferredity. You can set two different relationships between Customers and ORDERS, ORDERS, and Products. However, when you navigate for a Customer, you cannot jump from one Order to Related Products rows. Solution is to open the ORDERS / Products relationship, lock the ORDER you need, then get related rows. Do programmers need to store records in the ADO .NET and DataSet objects, You can work very well without causing troublesome in the "Storing An Ado Recordset in Git Might Cause.

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

New Post(0)