By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

DataReader

P: n/a
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
myOrderNo = reader.GetInt32(1);
}

instead of using reader.GetInt32(1), is there any syntax
that will support reader("OrderNo") or something like that?

Thanks for your help.

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item property in this case
that is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonewsgroup.net> wrote in message
news:03****************************@phx.gbl...
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
myOrderNo = reader.GetInt32(1);
}

instead of using reader.GetInt32(1), is there any syntax
that will support reader("OrderNo") or something like that?

Thanks for your help.

Nov 15 '05 #2

P: n/a
thanks a lot Ignacio. It worked.
-----Original Message-----
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item property in this casethat is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonewsgroup.net> wrote in message
news:03****************************@phx.gbl...
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
myOrderNo = reader.GetInt32(1);
}

instead of using reader.GetInt32(1), is there any syntax
that will support reader("OrderNo") or something like that?
Thanks for your help.

.

Nov 15 '05 #3

P: n/a
You can use the GetOrdinal property and assign it to a string. This way you
get the performance of the Index based approach with the readability of the
Literal name. like this...

DIM fieldCityPos as integer=reader1.getordinal("city")
Using the column slows things down because the column index needs to be
resolved each time a row is read...

HTH,

Bill
"lakshmi" <lm@newsgroup.net> wrote in message
news:89****************************@phx.gbl...
thanks a lot Ignacio. It worked.
-----Original Message-----
Hi,

I do it all the time !

Did you tried it?

Just a comment, remember that you are getting the Item

property in this case
that is the indexer , therefore you have to write
reader["OrderNo"] using [] instead of ()

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"lakshmi" <lm@replytonewsgroup.net> wrote in message
news:03****************************@phx.gbl...
Hi I'm using a SqlDataReader to read results from a SQL
view that returns 10 columns.
Is there anyway I can reader the columns based on their
names rather than their position?

strQuery = "SELECT customerid, orderno from orders where
orderID = 1";
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
myOrderNo = reader.GetInt32(1);
}

instead of using reader.GetInt32(1), is there any syntax
that will support reader("OrderNo") or something like that?
Thanks for your help.

.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.