Getting the index number of a column in a datarow in a strongly typed dataset...

P

Programatix

Hi.

I'm using a strongly typed dataset and I would like to get the index number
of a column from a datarow. Is that possible? I would like to avoid using
expression like this,

myTable.Columns.IndexOf("myColumnName")

Thanks.
 
C

Cor Ligthert [MVP]

Programatix,
I'm using a strongly typed dataset and I would like to get the index
number of a column from a datarow. Is that possible? I would like to avoid
using expression like this,

myTable.Columns.IndexOf("myColumnName")
What expression you like to avoid in this, this is a very normal VBNet
construction and therefore I do not understand it. This will however not
even be enough, you will have to use a fore index loop through the
columnnames which are than 3 rows of code.

Cor
 
P

Programatix

As I said, I'm using a strongly typed dataset. Anyway, I found out the way.
Goes something like this,

Let's assume that I have a dataset called dsDataset which a table called
dtTable. There is a column called ID in dtTable.

To retrieve the Index of the column ID,
dsDataset.dtTable.Columns.Indexof(dsDataset.dtTable.IDColumn)
 
P

Programatix

Now, I can't help wondering which one is faster.... too lazy to go and
benchmark them...
 

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