DataReader object in ADO.NET

xiaoxiao2021-03-06  77

C # examples are as follows: String Connstr = "provider = microsoft.jet.Oledb.4.; Data source =" server.mappath ("ASP_NET / ASP_NET.MDB"); string strsql = "select * from tb1"; OLEDBCONNECTION objConn = new OleDbConnection (connstr); OleDbCommand objComd = new OleDbCommand (strSql, objConn); objComd.Connection.Open (); // open Connection, Command operations necessary to open a database OleDbDataReader objRead = objComd.ExecuteReader (); // DataReader Not using new to generate objects, but use the OLEDBCOMMAND class to generate. i = 1; while objread.read () {if (i == 1) {response.write ("

); response.write (" "); Response.write (.....); //, write the title I = i 1;} else {response.write (" "); response.write (" < TD> " Objread.Item [1] .trim () " ") ... //}} Note: Generate OLEDBCOMMAND objects to create OLEDBCONNECTION (database connection), and produce OLEDBDATAREADER objects again The EXECUTEREADER () method of the OLEDBCommand object is generated, so there is a belonging between the three objects, and it will be declared in the beginning of the program. OLEDBDataReader has two important properties and a method that is Item [i], fieldcount property, and read method. In addition, OLEDBDataReader is very similar to the Recordset in the original ADO, but it is inadequate in the beauty: you can't get the name of the field.

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.037, SQL: 9