Variable and DataReader Question. Help Please. I looked everywhere. Thanks.

S

Shapper

Hello,

I have a DataReader which returns only one record from a database:

ID Name Content
12 hello world

Is it possible to create a variable named var_hello which value is
"world"?

It would be creating something like this:

var_[Name(ID)]=Content(ID) ,where ID=12.

I looked everywhere how to do this but I can't find a way.

Thank You,
Miguel
 
G

Guest

Hi Shapper,

You can use HashTable to store Key/Value pair in collection:

HashTable HtContent = new HashTable();
while (datareader.Read())
{
HtContent .Add(datareader["ID"], datareader["Content"]);
}

// then you can get Content by

string strContent = HtContent .Item[ID];

HTH

Elton Wang
(e-mail address removed)
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top