Ado. NET Access database

Source: Internet
Author: User
Here is the CSDN community Michael_jackson (Michael Jackson) post (delete the C # part), put here I want to be more useful to you!
You can use Ado.net DataReader to retrieve read-only, forward-only data streams from the database. Because there is always only one row in memory, using DataReader can improve application performance and reduce system overhead.
When you create an instance of a Command object, you can invoke Command.ExecuteReader to retrieve rows from the data source to create a DataReader, as shown in the following example.
[Visual Basic]
Dim myreader As SqlDataReader = Mycommand.executereader ()
Use the Read method of the DataReader object to get rows from the query results. You can access each column that returns rows by passing the column's name or ordinal reference to DataReader. However, for optimal performance, DataReader provides a series of methods that will allow you to access column values in the form of their native data types (GetDateTime, getdouble, GetGuid, GetInt32, and so on). For a list of typed accessor methods, see the OleDbDataReader class and the SqlDataReader class. Using a typed accessor method when the underlying data type is unknown will reduce the amount of type conversion required to retrieve the column values.
The following code example iterates through a DataReader object and returns two columns from each row.
[Visual Basic]
Do While Myreader.read ()
Console.WriteLine (VbTab & "{0}" & VbTab & "{1}", Myreader.getint32 (0), myreader.getstring (1))
Loop
Myreader.close ()
DataReader provides an buffered stream of data that enables procedural logic to efficiently process the results returned from the data source sequentially. Because data is not cached in memory, DataReader is an appropriate choice when retrieving large amounts of data.
Close DataReader
You should call the Close method each time you finish using the DataReader object.
If the Command contains output parameters or return values, these output parameters or return values will not be accessible until DataReader is closed.
Note that when DataReader is open, the DataReader will use Connection exclusively. You will not be able to execute any commands on Connection (including creating another DataReader) until the initial DataReader is closed.
Multiple result Sets
If more than one result set is returned, DataReader provides the NextResult method to iterate through the result sets sequentially, as shown in the following code example.
[Visual Basic]
Dim mycmd as SqlCommand = New SqlCommand ("Select CategoryID, CategoryName from Categories;" & _
"Select EmployeeID, LastName from Employees", nwindconn)

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.