473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to transfer form int index to string index

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
4 1854
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
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
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
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> ¼¶¼g©ó¶l¥ó·s»D: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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Moheb Missaghi | last post by:
Hi: I am trying to use the Transfer statement in an .aspx file to redirect and send Form and QueryString collections to a different page. A good example where this is needed is a checkout page...
11
by: Alexander Bosch | last post by:
Hi, I'm having a problem similar to the one that's stated in this KB http://support.microsoft.com/default.aspx?scid=kb;en-us;839521 When I'm posting a page to itself with the bool value as true it...
2
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi, I'm using Threads, and when I try to do Server.Transfer, I recieved an error. (child object does not exist...) My Code: Dim t As New Thread(AddressOf Hilo) Private Sub Hilo()...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.