Home All Groups Group Topic Archive Search About

Determining Column Number from Column Name

Author
24 Dec 2006 3:04 PM
Jeff
In .net2 using VB (Visual Web), I have the following code that properly
determines the column name from the column number (5 in this example) from a
single row table.

ColName = tempA.Table.Columns(5).ColumnName()

I can't figure out the code to return the column number if I have the column
name.

E.g., something like this:

ColNumber = tempA.Table.ColumnName(Y1).ColumnNumber()

Can someone point me in the right direction?

Thanks

Jeff


--
Posted via a free Usenet account from http://www.teranews.com

Author
24 Dec 2006 3:13 PM
vbnetdev
Loop through the columns and do a If ....Then and if it equals the column
name you are looking for then you have your column number.


Show quoteHide quote
"Jeff" <n***@none.com> wrote in message
news:458e8a4a$0$15523$88260bb3@free.teranews.com...
>
> In .net2 using VB (Visual Web), I have the following code that properly
> determines the column name from the column number (5 in this example) from
> a single row table.
>
> ColName = tempA.Table.Columns(5).ColumnName()
>
> I can't figure out the code to return the column number if I have the
> column name.
>
> E.g., something like this:
>
> ColNumber = tempA.Table.ColumnName(Y1).ColumnNumber()
>
> Can someone point me in the right direction?
>
> Thanks
>
> Jeff
>
>
> --
> Posted via a free Usenet account from http://www.teranews.com
>
Author
24 Dec 2006 4:00 PM
Jeff
"vbnetdev" <ad***@kjmsolutions.com> wrote in message
news:%23n6xI42JHHA.4068@TK2MSFTNGP03.phx.gbl...
> Loop through the columns and do a If ....Then and if it equals the column
> name you are looking for then you have your column number.


Thanks
After messing with this for a long while, I got the following to work.

CurColNumber = tempA.Table.Columns.IndexOf(ColName)



--
Posted via a free Usenet account from http://www.teranews.com
Author
24 Dec 2006 4:08 PM
Rad [Visual C# MVP]
On Sun, 24 Dec 2006 09:04:43 -0600, Jeff wrote:

Show quoteHide quote
> In .net2 using VB (Visual Web), I have the following code that properly
> determines the column name from the column number (5 in this example) from a
> single row table.
>
> ColName = tempA.Table.Columns(5).ColumnName()
>
> I can't figure out the code to return the column number if I have the column
> name.
>
> E.g., something like this:
>
> ColNumber = tempA.Table.ColumnName(Y1).ColumnNumber()
>
> Can someone point me in the right direction?
>
> Thanks
>
> Jeff

DataColumns have an Ordinal property. Could this be what you are looking
for?