In Asp.net, you can use datareader and dataset to read data from the database,
The differences between the two are as follows:
The following five steps are required to use a DataSet object to read data:
(1) Create a database connection. You can choose sqlconnection or 01 edbconnection.
(2) Save the query in the sqldataadapter or oledbdataadapter object.
(3) use the fill method of the dataadapter object to fill the data in the datatable in the dataset.
(4) create a dataview object for the datatable object to display data. This step can be omitted.
(5) bind dataview or dataset to server control.
The following six steps are required to use datareader to read data:
(1) Create a database connection. You can select sqlconnection or oledbconnection.
(2) Use the open method of the connection object to open the database link.
(3) Save the query in the sqlcommand or oledbcommand object.
(4) Call the executereader method of the command object to read data into the datareader object.
(5) Call the read or get method of datareader to read-pen data, so that the data is invisible.
(6) Call the close method of the connection object to close the data sequence link.
The first method has been used many times and is not described in detail here.
Next let's take a look at the use of the second method.
Oraclecommand ocmd = new oraclecommand ("select ID, fldname, caption, fldtype, maxlength, relatetbl, relateiterator, nvl (bnull, 1) from s_fields where tblname = '"+ name +"' ", ocon );
Oracledatareader ODA = ocmd. executereader ();
If (ODA. Read ())
{
This. textbox1.text = convert. tostring (ODA ["caption"]);
}
Ocon. Close ();