DataReader questions
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Bill Bassler
-- Moved from [aspngfreeforall] to [ngfx-sqlclient] by Marcie Jones <Click here to reveal e-mail address> --

1. What method to use when want to specify a fieldname instead of an
ordinal?

2. What are e.g. GetSqlInt32, GetSqlChar methods for? Should I use the
types fro efficiency's sake when using SQL Server?

* code snippets appreciated

Reply to this message...
 
    
Tim Curtin
reader("fieldname")

[Original message clipped]

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

Reply to this message...
 
    
Graham Dobson
. It is recommended that you use the typed accessor methods of the
DataReader when you know the specific type of the value being returned.
Typed accessor methods result in better performance by returning a value as
a specific .NET Framework type, eliminating the need for additional type
conversion. The SqlDataReader exposes SQL Server–specific typed accessor
methods if a .NET Framework type does not meet the needs of the application.
SQL Server–specific typed accessor methods return objects of
System.Data.SqlType. Not sure exactly what you mean by specifying field
names...All this can be read in the SDK under "Mapping .NET Data Provider
Data Types to .NET Framework Data Types"....

Graham

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 12:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] DataReader questions

-- Moved from [aspngfreeforall] to [ngfx-sqlclient] by Marcie Jones
<Click here to reveal e-mail address> --

1. What method to use when want to specify a fieldname instead of an
ordinal?

2. What are e.g. GetSqlInt32, GetSqlChar methods for? Should I use the
types fro efficiency's sake when using SQL Server?

* code snippets appreciated

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Bob Herrmann
Label1.Text = dr("CustomerName")

Where dr is the name of your datareader and CustomerName is a column name in
the table you accesssed with the datareader.

----- Original Message -----
From: "Bill Bassler" <Click here to reveal e-mail address>
To: "ngfx-sqlclient" <Click here to reveal e-mail address>
Sent: Tuesday, July 09, 2002 12:59 PM
Subject: [ngfx-sqlclient] DataReader questions

> -- Moved from [aspngfreeforall] to [ngfx-sqlclient] by Marcie Jones
<Click here to reveal e-mail address> --
[Original message clipped]

Reply to this message...
 
    
Bill Bassler
I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

Reply to this message...
 
    
ToddC@match.com
You are using C#, The complier may bee cool with it, but I don't the app
will. Try this instead:

private SqlDataReader m_dr;
sn = m_dr.GetString["sn"];
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString[0];

tc

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 2:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Trevor Pinkney
He's right. If you read the docs it only takes an int as an argument.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 4:19 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

You are using C#, The complier may bee cool with it, but I don't the app
will. Try this instead:

private SqlDataReader m_dr;
sn = m_dr.GetString["sn"];
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString[0];

tc

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 2:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Graham Dobson
SDK:You can access each column of the returned row by passing the name or
ordinal reference of the column to the DataReader. However, for best
performance, the DataReader provides a series of methods that allow you to
access column values in 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 the typed accessor
methods when the underlying data type is known will reduce the amount of
type conversion required when retrieving the column value.

Graham

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 3:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Tim Musschoot
Hello,

I'd do this:

private SqlDataReader m_dr;
sn = m_dr["sn"].ToString();

int a = int.Parse(m_dr["a_possible_int_field"].ToString());

It works good and fast, but there might be several options...

Tim Musschoot
AspFriends Moderation Team
Click here to reveal e-mail address
http://www.aspalliance.com/tim_musschoot

-----Oorspronkelijk bericht-----
Van: Graham Dobson [mailto:Click here to reveal e-mail address]
Verzonden: dinsdag 9 juli 2002 22:27
Aan: ngfx-sqlclient
Onderwerp: [ngfx-sqlclient] Re: DataReader questions

SDK:You can access each column of the returned row by passing the name or
ordinal reference of the column to the DataReader. However, for best
performance, the DataReader provides a series of methods that allow you to
access column values in 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 the typed accessor
methods when the underlying data type is known will reduce the amount of
type conversion required when retrieving the column value.

Graham

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 3:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
William \(Bill\) Vaughn (VIP)
The problem (as stated) with referencing the columns returned in the
DataReader via a string (that matches the column name) is one of
performance. My tests show a 1000 vs 234 difference. That is

    Myint = cint(dr("au_id") took 1000 units
While
    Myint = dr.GetInt32(0) too 234 units.

By changing the integer ordinal to an enumeration you get the human
readability back.

William (Bill) Vaughn
Author, trainer, mentor
Beta V Corporation
Redmond, Washington USA
www.betav.com
(425) 556-9205 (v/f)

-----Original Message-----
From: Tim Musschoot [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 2:45 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

Hello,

I'd do this:

private SqlDataReader m_dr;
sn = m_dr["sn"].ToString();

int a = int.Parse(m_dr["a_possible_int_field"].ToString());

It works good and fast, but there might be several options...

Tim Musschoot
AspFriends Moderation Team
Click here to reveal e-mail address
http://www.aspalliance.com/tim_musschoot

-----Oorspronkelijk bericht-----
Van: Graham Dobson [mailto:Click here to reveal e-mail address]
Verzonden: dinsdag 9 juli 2002 22:27
Aan: ngfx-sqlclient
Onderwerp: [ngfx-sqlclient] Re: DataReader questions

SDK:You can access each column of the returned row by passing the name
or
ordinal reference of the column to the DataReader. However, for best
performance, the DataReader provides a series of methods that allow you
to
access column values in 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 the typed
accessor
methods when the underlying data type is known will reduce the amount of
type conversion required when retrieving the column value.

Graham

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 3:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer
argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Bill Bassler
So it appears that my initial assumptions were correct??
The SqlDataReader is designed purely with speed in mind as reference via an
ordinal is
always going to be faster than a field collection lookup. So that available
methods point you in that direction.
You just have to be a bit more careful.

"William (Bill) Vaughn" <Click here to reveal e-mail address> wrote in message
news:681217@ngfx-sqlclient...
[Original message clipped]

Reply to this message...
 
    
Bill Bassler
Sure enough. It works my guess is that it's a tad slower.
Whether it's 2/3 slower than the test William Vaughn (see this thread) I
don't know.

Thanks

"Tim Musschoot" <Click here to reveal e-mail address> wrote in message
news:681183@ngfx-sqlclient...
[Original message clipped]

Reply to this message...
 
    
Russ McClelland
WW91IGNvdWxkIGNyZWF0ZSBhIGhhc2h0YWJsZSB3aXRoIHRoZSBTdHJpbmcgbmFtZSBhcyB0aGUg
a2V5IGFuZCB0aGUNCm9yZGluYWwgYXMgdGhlIHZhbHVlIHNvIHRoYXQgeW91IGNvdWxkIHVzZSB0
aGUgZmFzdCBhY2Nlc3NvcnMsIGJ1dCB0aGVuDQp5b3UgaGF2ZSB0byBtYWludGFpbiB0aGF0IGxp
c3QgYXMgaXQgZXZvbHZlcyBvdmVyIHRpbWUuICBUaGUgYmVuZWZpdHMgb2YNCnNwZWVkIGRvbid0
IHNlZW0gdG8gb3V0d2VpZ2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mVyIGdyYWhhbWRvQGF0dGNhbmFkYS5jYSA9IFlPVVIgSUQNCgk+IHwgaHR0
cDovL3d3dy5hc3BmcmllbmRzLmNvbS9hc3BmcmllbmRzL25nZngtc3FsY2xpZW50LmFzcCA9DQpK
T0lOL1FVSVQNCgk+DQoJPg0KCT4gfCBbbmdmeC1zcWxjbGllbnRdIG1lbWJlciBUaW0ubXVzc2No
b290QHJ1Zy5hYy5iZSA9IFlPVVIgSUQNCgk+IHwgaHR0cDovL3d3dy5hc3BmcmllbmRzLmNvbS9h
c3BmcmllbmRzL25nZngtc3FsY2xpZW50LmFzcCA9DQpKT0lOL1FVSVQNCgk+DQoJPg0KCT4gfCBb
bmdmeC1zcWxjbGllbnRdIG1lbWJlciBiaWxsdmFAbndsaW5rLmNvbSA9IFlPVVIgSUQNCgk+IHwg
aHR0cDovL3d3dy5hc3BmcmllbmRzLmNvbS9hc3BmcmllbmRzL25nZngtc3FsY2xpZW50LmFzcCA9
DQpKT0lOL1FVSVQNCgk+DQoJPg0KCT4NCgk+DQoJDQoJDQoJDQoJfCBbbmdmeC1zcWxjbGllbnRd
IG1lbWJlciBydXNzLm1jY2xlbGxhbmRAc21hcnRvYmp4LmNvbSA9IFlPVVINCklEDQoJfCBodHRw
Oi8vd3d3LmFzcGZyaWVuZHMuY29tL2FzcGZyaWVuZHMvbmdmeC1zcWxjbGllbnQuYXNwID0NCkpP
SU4vUVVJVA0KCQ0KDQo
Reply to this message...
 
    
ToddC@match.com
Doh!!, your right.

GetString() is a method call, and you must use Parenthesis not brackets, and
the docs do call for int.

My apologies if I lead anyone a astray....

tc

-----Original Message-----
From: Trevor Pinkney [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 3:20 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

He's right. If you read the docs it only takes an int as an argument.

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 4:19 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

You are using C#, The complier may bee cool with it, but I don't the app
will. Try this instead:

private SqlDataReader m_dr;
sn = m_dr.GetString["sn"];
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString[0];

tc

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 2:59 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

I'm using the SqlDataReader class.
The .GetString method for example appear to only take an integer argument as
a parameter.

e.g
private SqlDataReader m_dr;
sn = m_dr.GetString("sn");
Build error: Argument '1': cannot convert from 'string' to 'int'

where as:
private SqlDataReader m_dr;
sn = m_dr.GetString(0);

compiles fine.

Am I missing something?

"Bill Bassler" <Click here to reveal e-mail address> wrote in message
news:681037@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
ToddC@match.com
No, create an enum for the column ID's. Much better than an array.

Here is where speed and maintainability don't equal the same thing.

In ADO.OLD, I would create enums for the same purpose. It was, and =
still is
worth the effort. (IMO) not very difficult to keep up with.

tc

-----Original Message-----
From: Russ McClelland [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 10, 2002 10:40 AM
To: ngfx-sqlclient
Subject: RE: [ngfx-sqlclient] Re: DataReader questions

You could create a hashtable with the String name as the key and the =
ordinal
as the value so that you could use the fast accessors, but then you =
have to
maintain that list as it evolves over time.=A0 The benefits of speed =
don't
seem to outweigh the maintenance issues that arise (to me)...
-----Original Message-----=20
From: Bill Bassler=20
Sent: Wed 7/10/2002 6:31 AM=20
To: ngfx-sqlclient=20
Cc:=20
Subject: [ngfx-sqlclient] Re: DataReader questions
So it appears that my initial assumptions were correct??
The SqlDataReader is designed purely with speed in mind as reference =
via an
ordinal is
always going to be faster than a field collection lookup. So that =
available
methods point you in that direction.
You just have to be a bit more careful.

"William (Bill) Vaughn" <Click here to reveal e-mail address> wrote in message
news:681217@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address =3D YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp =3D JOIN/QUIT

Reply to this message...
 
    
ToddC@match.com
Now that I say that, looking at the docs, there is a bunch, well three
interfaces that are implemented by the enum class. It does inherit from
value type, but the docs say it is not a value type. Seems to me if it
inherits from ValueType, then it is of type ValueType (OOP).

Would make an interesting exercise to see which is faster to use:
Array
Enum
Int Variables

I would suppose that Int variables would be faster, followed by enum,
followed by Array, but It would need some testing to proof out.

tc

-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 12:14 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

No, create an enum for the column ID's. Much better than an array.

Here is where speed and maintainability don't equal the same thing.

In ADO.OLD, I would create enums for the same purpose. It was, and still is
worth the effort. (IMO) not very difficult to keep up with.

tc

-----Original Message-----
From: Russ McClelland [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 10:40 AM
To: ngfx-sqlclient
Subject: RE: [ngfx-sqlclient] Re: DataReader questions

You could create a hashtable with the String name as the key and the ordinal
as the value so that you could use the fast accessors, but then you have to
maintain that list as it evolves over time.  The benefits of speed don't
seem to outweigh the maintenance issues that arise (to me)...
-----Original Message-----
From: Bill Bassler
Sent: Wed 7/10/2002 6:31 AM
To: ngfx-sqlclient
Cc:
Subject: [ngfx-sqlclient] Re: DataReader questions
So it appears that my initial assumptions were correct??
The SqlDataReader is designed purely with speed in mind as reference via an
ordinal is
always going to be faster than a field collection lookup. So that available
methods point you in that direction.
You just have to be a bit more careful.

"William (Bill) Vaughn" <Click here to reveal e-mail address> wrote in message
news:681217@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT
Reply to this message...
 
    
Minh Truong
[Original message clipped]

Any ordinal access is going to be faster than a string lookup, whether it be
in a DataReader or another collection.
A DataReader primary advantage is that it doesn't download all records into
memory like a Dataset would.

Reply to this message...
 
    
Bill Bassler
RE: [ngfx-sqlclient] Re: DataReader questionsAll. If you didn't notice,
take a look at William (Bill) Vaughn's response for a rough benchmarks.

BTW. If you didn't see it, the ToString method for the SqlDataReader will
buy you use of a field name instead of ordinal. It seems the SqlDataReader
does maintain some sort of enum, array or collection of the returned
fieldnames. The "Get" methods just don't seem to directly support its use??
Use at what cost. Unknown.

// THIS WORKS
private SqlDataReader m_dr;
sn = m_dr["sn"].ToString();

<Click here to reveal e-mail address> wrote in message news:681661@ngfx-sqlclient...
Now that I say that, looking at the docs, there is a bunch, well three
interfaces that are implemented by the enum class. It does inherit from
value type, but the docs say it is not a value type. Seems to me if it
inherits from ValueType, then it is of type ValueType (OOP).
Would make an interesting exercise to see which is faster to use:
Array
Enum
Int Variables
I would suppose that Int variables would be faster, followed by enum,
followed by Array, but It would need some testing to proof out.
tc
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 12:14 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions
No, create an enum for the column ID's. Much better than an array.
Here is where speed and maintainability don't equal the same thing.
In ADO.OLD, I would create enums for the same purpose. It was, and still is
worth the effort. (IMO) not very difficult to keep up with.
tc
-----Original Message-----
From: Russ McClelland [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 10:40 AM
To: ngfx-sqlclient
Subject: RE: [ngfx-sqlclient] Re: DataReader questions
You could create a hashtable with the String name as the key and the ordinal
as the value so that you could use the fast accessors, but then you have to
maintain that list as it evolves over time. The benefits of speed don't
seem to outweigh the maintenance issues that arise (to me)...
-----Original Message-----
From: Bill Bassler
Sent: Wed 7/10/2002 6:31 AM
To: ngfx-sqlclient
Cc:
Subject: [ngfx-sqlclient] Re: DataReader questions
So it appears that my initial assumptions were correct??
The SqlDataReader is designed purely with speed in mind as reference via an
ordinal is
always going to be faster than a field collection lookup. So that available
methods point you in that direction.
You just have to be a bit more careful.
"William (Bill) Vaughn" <Click here to reveal e-mail address> wrote in message
news:681217@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT
| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
ToddC@match.com
Correct, Bill has done a bunch of benchmarking and has a great wealth of
knowledge.

His reference was about the fastest method to access the column using the
GetString() method. This method takes a value of type Int.

My post was in reference to a human readable way to specify the Int. Bill
mentioned using an Enum, and Russ had mentioned using an array. I would
imagine that an Enum is much faster than the Array, due mainly because an
array doesn't have a provision for looking up an index based on a key. You
still have to index the Array to find the Int to stick in the GetString
method. You may also need to cast the value from the Array.

This is where the Enum would be faster; it basically has an indexing
provision, and would not need to be type casted. That being said, it is
inherited from Value Type, and implements three interfaces. None of this
screams speed, but it also doesn't necessarily mean they are slow either.
Your mileage may vary. Since Int is a base type, or rather not a class, it
should be faster than the Enum, and not really that much more trouble to
keep up with than the Enum.

Again, I am theorizing here, and not speaking from hard data.

tc

-----Original Message-----
From: Bill Bassler [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 1:08 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

RE: [ngfx-sqlclient] Re: DataReader questionsAll. If you didn't notice,
take a look at William (Bill) Vaughn's response for a rough benchmarks.

BTW. If you didn't see it, the ToString method for the SqlDataReader will
buy you use of a field name instead of ordinal. It seems the SqlDataReader
does maintain some sort of enum, array or collection of the returned
fieldnames. The "Get" methods just don't seem to directly support its use??
Use at what cost. Unknown.

// THIS WORKS
private SqlDataReader m_dr;
sn = m_dr["sn"].ToString();

<Click here to reveal e-mail address> wrote in message news:681661@ngfx-sqlclient...
Now that I say that, looking at the docs, there is a bunch, well three
interfaces that are implemented by the enum class. It does inherit from
value type, but the docs say it is not a value type. Seems to me if it
inherits from ValueType, then it is of type ValueType (OOP).
Would make an interesting exercise to see which is faster to use:
Array
Enum
Int Variables
I would suppose that Int variables would be faster, followed by enum,
followed by Array, but It would need some testing to proof out.
tc
-----Original Message-----
From: Click here to reveal e-mail address [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 12:14 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions
No, create an enum for the column ID's. Much better than an array.
Here is where speed and maintainability don't equal the same thing.
In ADO.OLD, I would create enums for the same purpose. It was, and still is
worth the effort. (IMO) not very difficult to keep up with.
tc
-----Original Message-----
From: Russ McClelland [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 10:40 AM
To: ngfx-sqlclient
Subject: RE: [ngfx-sqlclient] Re: DataReader questions
You could create a hashtable with the String name as the key and the ordinal
as the value so that you could use the fast accessors, but then you have to
maintain that list as it evolves over time. The benefits of speed don't
seem to outweigh the maintenance issues that arise (to me)...
-----Original Message-----
From: Bill Bassler
Sent: Wed 7/10/2002 6:31 AM
To: ngfx-sqlclient
Cc:
Subject: [ngfx-sqlclient] Re: DataReader questions
So it appears that my initial assumptions were correct??
The SqlDataReader is designed purely with speed in mind as reference via an
ordinal is
always going to be faster than a field collection lookup. So that available
methods point you in that direction.
You just have to be a bit more careful.
"William (Bill) Vaughn" <Click here to reveal e-mail address> wrote in message
news:681217@ngfx-sqlclient...
[Original message clipped]

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT
| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Minh Truong
> BTW. If you didn't see it, the ToString method for the SqlDataReader
will
[Original message clipped]

This is actually not the ToString() of the DataReader. What you're doing
here is

1) Get the Object represented by m_dr["sn"]
2) Get the string representation of that object via ToString()
3) Assign that string to variable "sn"

I'm not sure how ADO.NET implements the assessor for the DataReader, but if
I were to do it, I'd do an array indexer for ordinal access. This would be
the fastest way to get a value out of a collection. I'd then implement a
field name lookup that returns a field ordinal.

Reply to this message...
 
    
Alex Dresko
If I learned what I learned correctly yesterday, the REASON ordinal
access is faster because specifying a string name for the field forces
the DataReader to use the reflection APIs to gather information about
itself.

Just a side note there... :)

Alex Dresko
Three Point Oh!

-----Original Message-----
From: Minh Truong [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 10, 2002 1:32 PM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] Re: DataReader questions

[Original message clipped]

an
[Original message clipped]

Any ordinal access is going to be faster than a string lookup, whether
it be
in a DataReader or another collection.
A DataReader primary advantage is that it doesn't download all records
into
memory like a Dataset would.

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
 
System.Data.OleDb.OleDbDataReader
System.Data.SqlClient.SqlDataReader
System.ValueType




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com