DataReader rows into a collection object

Hi,

I have a datreader object with 100 rows,  i created a collection object[ arraylist / hashtable] and stored all the rows to the collection object.

I dont want to keep the connection opened that's the reason  i stored the data to the collection object and killed the datareader object.

But the problem is I wanted to retrieve the value using column names not by index. For this I looped thru the column names from datareader, how do I merge these two objects

Any help is highly appreciated.




Answer this question

DataReader rows into a collection object

  • horatiug

    The datareader gets the data....the datatables persist the data in structured memory...you can also utilize  custom classes/objects (business entities) to do the same thing as a datatable...

    <quote>But the problem is I wanted to retrieve the value using column names not by index. For this I looped thru the column names from datareader, how do I merge these two objects </>



    While MyReader.Read
    For x As Integer = 0 To Myreader.FieldCount - 1

    MyObject.FieldArray(x) = Myreader(x)

    Next
    loop

     



    If you want to do this with column names then I would suggest using an array of names also....something like this:



    While MyReader.Read
    For x As Integer = 0 To Myreader.FieldCount - 1

    MyObject.FieldArray(x) = Myreader(MyColumnNames(x))

    Next
    loop


     




  • HAFB

    Now I'm confused ... If you're not using databases, why use DataReaders at all  

  • arunr2002

    Why not just use a DataTable   The following link works well if you're using VS.NET 2003 or before ...
    http://codebetter.com/blogs/grant.killian/archive/2004/03/23/9819.aspx

    Or you could just run the SQL to populate the DataTable directly.  I find this much easier ...

    Josh

  • Hf Kok

    Hi Josh,

    We don't use datatables in our application, we use custom objects.

  • DataReader rows into a collection object