Index column in Dataset (or Datareader) !!!!

G

Guest

When I put the a Select command result into a dataset (or datareader), I have
to inform which column index I want to work with...thats pretty akward ,
since I have to know in advance exactly the order the column appears in
Select command. It gets complicated if we r talking of 30 columns. In ancient
VB, I would use Enums to help in this, is there any intelligent way in .NET
to solve this topic?

Thanks to all !
 
W

W.G. Ryan eMVP

Bruce - I'm not sure I follow you. Are you talking about the Sql Statement
you're firing against the db or datatable.select/ B/c you mention a reader
I'm guessing it's the latter. If so, I'd first caution you about using 30
columns. Unless you really need all of them, just pull back what you need
b/c there is overhead. What do you need the index for client side though?
ARe you talking about query hints of some sort or is it something else?
Perhaps if you can tell me a little more about the scenario I can be more
helpful.
 
S

Scott M.

Why can't you just refer to the column by the column name (which is taken
from the field name in the SQL statement)?
 
C

Cor Ligthert [MVP]

Bruce,

You are talking about apples and pears as the same

Datasets and datareader.

The first one is a class that wraps around datatables and relation to store
these,
The second one is a active method to get data from a database.

The first one is full of all kind of indexes.

Can you explain for us more what you mean?

Cor
 
G

Guest

Because I would have to memorize its names...I thought I could create a
solution (like an intellisense browser) so that I wouldnt have to know column
names or its position in Select command. In old VB I would solve this by
using Enums....

Thanks!
 
G

Guest

I agree 30 columns in a Select is too much. But lets consider 5 columns then.
I have 2 options: 1) by knowing column names, I would refer to them
explcitily in dataset/datareader. 2) I would use index to refer to them.

Is 1st case, I would have to memorize column names (or have them written
down in some paper). In 2nd case, I would have to memorize column position in
Select command.
 
S

Scott M.

Then what about a strongly-typed dataset? This will list your table and
column names in the intellisense.
 
W

W.G. Ryan eMVP

YOu can use typed datasets which will fix this for you via intellisense. THe
other case, as the illustrious Bill Vaughn recommends, is creating an
enumeration corresponding to the column indexes. This gives you column names
via intellisense and the performance of index based lookups.
 
W

W.G. Ryan eMVP

In most cases though- use a Typed dataset, this is the easiest approach.
When you use datareaders, use the enums.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top