Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Loading Array from Dataset

I'm tyring to load an array from a dataset. There are 10 records in the dataset. What I'm doing is setting a datarow and looping through this dataset and trying to add each row to an array. Not sure how to do this?

Also, If I wanted to skip the array all together, when I loop through the dataset how do I add each row individually to another dataset?

thanks for the help

jb
[415 byte] By [jcb1269] at [2007-11-11 9:53:48]
# 1 Re: Loading Array from Dataset
It all depends on what format your data set is in. If your dataset is going to be varying in elements, all you have to do is:

dim myArr()

y=0
For Each item In DataSet
ReDim Preserve myArr(y)
myArr(y) = item
y=y+1
Next
thepip3r at 2007-11-11 21:45:10 >
# 2 Re: Loading Array from Dataset
My dataset has 3 fields in it, all are strings, 10 records total. I would like each element in the array to be a row from the dataset. Is this possible?
jcb1269 at 2007-11-11 21:46:10 >
# 3 Re: Loading Array from Dataset
but where is your data stored? are we talking database, flat file, etc. if it's a database, dumping the information into the array will depend on your query. if it's a flat file, it will depend on how the information is presented on each line.
thepip3r at 2007-11-11 21:47:14 >
# 4 Re: Loading Array from Dataset
Sorry.. It's coming from a sql server database. I have the array loaded with the data, when I do a datagridview.datasource = arrayname it just puts the lenght of each element in the first column.
jcb1269 at 2007-11-11 21:48:19 >
# 5 Re: Loading Array from Dataset
can you post the snippet of code dealing with the problem pls.
thepip3r at 2007-11-11 21:49:22 >
# 6 Re: Loading Array from Dataset
Thanks for the help. I figured out. I had to create my columns programmatically then create my array then add it to the grid. Sorry for the frustration.. :(
jcb1269 at 2007-11-11 21:50:21 >