|
-
Mar 21st, 2002, 04:01 PM
#1
Thread Starter
Junior Member
datagrid values into an array
how wood i get the results of my qeury into an array.
Example.. my query returned the field "order". thgere are 130 records that werer returned in that field. i want those values to be put into an array.
Oder
1
2
3
4
5
etc.... array wood contain 1,2,3,4,5 etc..
thax
trin
-
Mar 21st, 2002, 04:27 PM
#2
easiest way would be to ReDim an array of the appropriate type to the number of records.
Assume rs is the recordset:
Code:
Dim NumAry()
...
...
redim NumAry(rs.recordcount)
while not rs.eof
NumAry(rs.absoluteposition)=rs.fields("fieldname").value
rs.movenext
wend
...
ReDim will set the lowerlimit to 0 and the upper limit to the
number of records in the dataset. You, however, DO NOT have to
use the zeroth element.
HTH
-
Mar 22nd, 2002, 09:52 AM
#3
Thread Starter
Junior Member
that worked great thanx, but i have one question..its silly question but here goes..this is my code..
Code:
Private Sub cmdArray_Click()
Dim elements As Integer
Dim Numarray() As String
elements = Adodc1.Recordset.RecordCount
ReDim Numarray(elements)
While Not Adodc1.Recordset.EOF
Numarray(Adodc1.Recordset.AbsolutePosition) = Adodc1.Recordset.Fields("Exam_order").Value
Adodc1.Recordset.MoveNext
Wend
lblArray = Numarray(1)
how do u declare "rs" in your example. I dont want to have to tpye out adodc1.recordset.blah blah. everytime in my code.I want to use rs. eof for example like you have in your example.
thanx
trin
-
Mar 22nd, 2002, 12:50 PM
#4
Here it goes...
Here is an example of what I do:
VB Code:
Dim rc as recordset
Set rc = adodc1.recordset
'then...
a = rc.fields("yourfield")
b = rc.recordcount
'etc....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|