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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.