How can I store the results of a DataReader into an array, but still be able to reference them by column name? I essentially want to be able to clone the DataReader’s content so that I can close the reader and still have access. I don’t want to store the items in a DataTable like everyone suggests.
I’ve seen a lot of answers, but I couldn’t really find any for what I wanted
The easiest way I’ve found to do this is by populating the array with dictionaries with Strings as keys and Objects as values, like so:
So, now you could loop through result with a for loop like this:
Quite similar to how you would do it if it were just the DataReader:
This example is using the MySQL/NET driver, but the same method can be used with the other popular database connectors.