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

How to transfer form int index to string index

P: n/a
ad
When we user SqlDataReader, we can use integer or string as index.
For example, if the query string is :
Select Math, Nature, Social form Scores"
and the myRD is the SqlDataReader,
We can refer a field by myRD[0], or myRD["Math"]

But how can we get the string index for the integer index.
For example,

sting sPassSubjects
for (int i=0; i<3, i++)
{
if (myRD[i]>60)
sPassSubjects+=GetSubject(i);
}

The GetSubject function can return a subject for index, like if i=0, then
return "Math",
i=2, return Social.

How can I write this function?


Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Once you’ve got your DataReader, call it’s GetName() method passing in the
index of the column you want the name of.

Brendan
"ad" wrote:
When we user SqlDataReader, we can use integer or string as index.
For example, if the query string is :
Select Math, Nature, Social form Scores"
and the myRD is the SqlDataReader,
We can refer a field by myRD[0], or myRD["Math"]

But how can we get the string index for the integer index.
For example,

sting sPassSubjects
for (int i=0; i<3, i++)
{
if (myRD[i]>60)
sPassSubjects+=GetSubject(i);
}

The GetSubject function can return a subject for index, like if i=0, then
return "Math",
i=2, return Social.

How can I write this function?


Nov 17 '05 #2

P: n/a
Hi,

myRdr.GetOrdinal("Math") returns 0, and myRdr.GetName(0) returns "Math".

Regards - Octavio

"ad" <ad@wfes.tcc.edu.tw> escribi en el mensaje
news:%2***************@TK2MSFTNGP09.phx.gbl...
When we user SqlDataReader, we can use integer or string as index.
For example, if the query string is :
Select Math, Nature, Social form Scores"
and the myRD is the SqlDataReader,
We can refer a field by myRD[0], or myRD["Math"]

But how can we get the string index for the integer index.
For example,

sting sPassSubjects
for (int i=0; i<3, i++)
{
if (myRD[i]>60)
sPassSubjects+=GetSubject(i);
}

The GetSubject function can return a subject for index, like if i=0, then
return "Math",
i=2, return Social.

How can I write this function?

Nov 17 '05 #3

P: n/a
Hi,
In general you cannot do that, at least directly, the reason is that it;s
dependand of the way the indexer is implemented, The string can be any
property of the type in the collection. just post back if you are further
interested in this.

In any case, you are lucky :) using SqlReader you can get the name of the
column using myRD.GetName( int index );
cheers,

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

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
When we user SqlDataReader, we can use integer or string as index.
For example, if the query string is :
Select Math, Nature, Social form Scores"
and the myRD is the SqlDataReader,
We can refer a field by myRD[0], or myRD["Math"]

But how can we get the string index for the integer index.
For example,

sting sPassSubjects
for (int i=0; i<3, i++)
{
if (myRD[i]>60)
sPassSubjects+=GetSubject(i);
}

The GetSubject function can return a subject for index, like if i=0, then
return "Math",
i=2, return Social.

How can I write this function?

Nov 17 '05 #4

P: n/a
ad
Thanks,

I use DotNetFrameWork 2.0.
There is a FormViewUpdatedEventArgs in the ItemUpdated event of a FormVew:
ItemUpdated(object sender, FormViewUpdatedEventArgs e)
I can use both integer or string as index, like
e.NewValues[0], or e.NewValues["Math"], but I found I can use
e.NewValues.GetName(0) to return "Math".

If there any way to get it?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> glsD:eQ**************@TK2MSFTNGP10.phx.g bl...
Hi,
In general you cannot do that, at least directly, the reason is that it;s
dependand of the way the indexer is implemented, The string can be any
property of the type in the collection. just post back if you are further
interested in this.

In any case, you are lucky :) using SqlReader you can get the name of
the column using myRD.GetName( int index );
cheers,

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

"ad" <ad@wfes.tcc.edu.tw> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
When we user SqlDataReader, we can use integer or string as index.
For example, if the query string is :
Select Math, Nature, Social form Scores"
and the myRD is the SqlDataReader,
We can refer a field by myRD[0], or myRD["Math"]

But how can we get the string index for the integer index.
For example,

sting sPassSubjects
for (int i=0; i<3, i++)
{
if (myRD[i]>60)
sPassSubjects+=GetSubject(i);
}

The GetSubject function can return a subject for index, like if i=0, then
return "Math",
i=2, return Social.

How can I write this function?


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.