How to transfer form int index to string index

  • Thread starter Thread starter ad
  • Start date Start date
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>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?
 
Once you’ve got your DataReader, call it’s GetName() method passing in the
index of the column you want the name of.

Brendan
 
Hi,

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

Regards - Octavio
 
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,
 
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 ) said:
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 said:
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>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?

 

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

Back
Top