Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datareaders

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
How would I take the contents of a datareader and store one of the fields in the table into an array?
 
usually if i feel the need to drop a datareader into an array, I'll first build up comma separated lists, and then split those.

problem is, if the size of the dr is dynamic, there's no .count() property, so you never know how big to make the array. Consider this logic instead:

~~~~~~~
'making datareader (dr)
~~~~~~~
dim sb as new stringBuilder()
while dr.read
sb.append(dr("fieldName"))
sb.append(",")
wend
dim temp as string()
if not sb.tostring = string.empty then
temp = sb.tostring.substring(0,sb.tostring.length-1).split(",")
else
redim temp(1)
temp(0) = string.empty
end if

and then all your "fieldName" column values are nice and neat in your array -- just remember to hack off that last comma on your string, like I've shown.

good luck! :)
paul
penny1.gif
penny1.gif
 
One technique, which may or may not be applicable in our case, is to fill the arry using the reader, e.g.,
...
Dim arrMyfield As ArrayList
arrMyfield = New ArrayList(j)
Dim UpdateReader As OleDbDataReader = sqlCmd.ExecuteReader()
Do While Reader.Read()
arrMyfield.Add(Reader.GetValue(0))
Reader.Close()
dbconn.Close()
...
Paul, great solution, will try it -- you've been a big help to a lot people here -- keep up the good work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top