My example above will simply write out all your records row by row.
You can manipluate the data any you need.
To call information from the dataset you need to reference the table and the the row and column you want..so:
ds.Tables(TableIndex).Rows(rowIndex)(columnIndex).ToString will return a string with the value for the index specified.
If you want the value stored in row 2 column 5 of Table 0 you would call:
ds.Tables(0).Rows(2)(5).ToString
Your dataset like a database can house multiple tables. So you could in theory return multiple record sets from a single stored procedure into the dataset then based on the order they were returned reference the index of that table then the row and column
you want.
By looping with a for each row and then for each column we will get all of the data from top to bottom.
Let me know if you need more info. SqlDataReader is not going to be as friendly for this. You could build up an array with all the values as you progress through your reader then call that array again later but it's much more code and not as easy to work
with.
Loganix77
Participant
1351 Points
412 Posts
Re: Looping thorough a query and storing the row values in a Dictonary or someother object
May 04, 2012 09:30 PM|LINK
My example above will simply write out all your records row by row.
You can manipluate the data any you need.
To call information from the dataset you need to reference the table and the the row and column you want..so:
ds.Tables(TableIndex).Rows(rowIndex)(columnIndex).ToString will return a string with the value for the index specified.
If you want the value stored in row 2 column 5 of Table 0 you would call:
ds.Tables(0).Rows(2)(5).ToString
Your dataset like a database can house multiple tables. So you could in theory return multiple record sets from a single stored procedure into the dataset then based on the order they were returned reference the index of that table then the row and column you want.
By looping with a for each row and then for each column we will get all of the data from top to bottom.
Let me know if you need more info. SqlDataReader is not going to be as friendly for this. You could build up an array with all the values as you progress through your reader then call that array again later but it's much more code and not as easy to work with.
Cheers!