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

Discussion in 'ASP .Net' started by Shapper, Apr 22, 2005.

  1. Shapper

    Shapper Guest


    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

    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,
    Shapper, Apr 22, 2005
    1. Advertisements

  2. Shapper

    Guest 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];


    Elton Wang
    Guest, Apr 23, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.