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.