ASP.NET & Databases Part 1
page 4 of 7
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 33363/ 50

Data Reader

Data Reader
 

The OleDbDataReader is a way to read data, not write or update, but read. It streams the data (unlike a dataset) so is a bit limited to use, but for very simple data reading (i.e. display of data) its perfect.
 

Dim objReader as OleDbDataReader
objReader = objCmd.ExecuteReader

 

While objReader.Read
      Response.Write(objReader.GetString(0) & "<br>")
End While


The top one shows you what we've already done before - Using the Command to fill the Data Reader.
The bottom one displays the data for us. The Read method keeps on reading each line of the results and stops when there are no more. objReader.GetString(0) tells it to get the string version of the first column of the current record (columns start a 0).

Here is a list of the Get[thing](index).

·         GetBoolean(x)

·         GetByte(x)              - Returns it as a Byte value

·         GetBytes(x)            - Returns it as a Byte array

·         GetChar(x)              - Returns char value

·         GetChars(x)            - Returns char array

·         GetDataTypeName(x) - Returns the data type of the specified column

·         GetDateTime(x)

·         GetDecimal(x)

·         GetDefaultStream(x) - Returns a Stream object

·         GetDouble(x)

·         GetFieldType(x)       - Get the Type that is the data type of the object

·         GetFloat(x)

·         GetGuid(x)               - Retunrs the value as a Globally Unique Idetifier Value (GUID)

·         GetInt16(x)

·         GetInt32(x)

·         GetInt64(x)

·         GetName(x)              - Returns the name of the column

·         GetOrdinal(name)      - Returns the column index as given by the column name

·         GetString(x)

·         GetTimeSpan(x)

·         GetValue(x)               - Returns the data in its native format

·         GetValues(values())    - Returns all attributes for the column and places them in values()

Now that is a lot of methods just for getting a value, they take up about 90% of all of the Data Reader's methods. I've put a small explanation on the ones that aren't that obvious.
 


View Entire Article

User Comments

Title: Re: One comment   
Name: Philip Q
Date: 2004-10-25 11:08:14 PM
Comment:
Jen,

The reason for that is that you have imported System.Data, but not System.Data.OleDb into your page.
Title: One comment.   
Name: Jen
Date: 2004-10-25 9:33:47 AM
Comment:
Putting the OleDBConnection command into the page_load event gives the error that OleDBConnection is not defined. However, OleDb.OleDbConnection works.
Title: Good...how to work with more than one dataset   
Name: Santhosh Kumar A.
Date: 2004-10-19 6:41:29 AM
Comment:
I found it very good. Please try to include how
to manipulate rows using For Each ... Next loop.
I was really searching for it.

Santhosh Kumar A.
Kerala, India

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-17 11:27:28 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search