Two Methods for reading databases in Asp.net

Source: Internet
Author: User
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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.