|
-
Oct 29th, 2000, 01:43 PM
#1
Thread Starter
Addicted Member
I want to put the data returned from an SQL query to an array.
As far as I know I can get the data if it's only a single value like this:
Code:
Text1.text = rc.Fields("xyz")
But if there are more values returned it doesn't work because only the first value is shown in the text field.
Now, if I got a table called users and I want to know the names of all users who have blue hair I would try this:
Code:
Dim db As Database
Dim rs As Recordset, SQL$
Set db = OpenDatabase("C:\My Documents\mytestdb.mdb")
SQL = "SELECT username FROM users where haircolor like ""blue"""
Set rs = db.OpenRecordset(SQL)
But how can I put the names returned (and the other stuff) to an array like this:
Code:
Type TUser
username as String
haircolor as String
password as String
End Type
Dim userlist() as TUser
Razzle
ICQ#: 31429438
What is the difference between a raven?
-The legs. The length is equal, especially the right one. 
-
Oct 29th, 2000, 03:32 PM
#2
what you want can't be done that way, but you could use GetString to get a complete recordset into a string with delimiters to get a similar result.
best regards
Sascha
-
Oct 29th, 2000, 03:53 PM
#3
Thread Starter
Addicted Member
Of which object is GetString a method?
I couldn't find it at db (Database) nor at rs (recordset)
Razzle
ICQ#: 31429438
What is the difference between a raven?
-The legs. The length is equal, especially the right one. 
-
Oct 29th, 2000, 05:55 PM
#4
GetString is a method of ADODB-recordsets, so you could swithch from DAO to ADO.
mfg
Sascha
-
Oct 30th, 2000, 02:26 AM
#5
Well Razzle, your sql statement needs to be modified...
SQL = "SELECT username,password,haircolor FROM users where haircolor like ""blue"""
In ur sql query you are selecting only the username into the recordset. Try the above query and you can get the data in the fields using
recordset.fields(index).value
Even in the above query the haircolor will be blue as u r retrieving the records where haircolor is blue. So please look into it and u can always improve on it...
keep in touch...
With regards...vijay.
-
Oct 30th, 2000, 12:08 PM
#6
i forgot to mention, when using DAO, you could still use rs.GetRows to get the complete Recordset into a 2-dimensional array. That's maybe not too efficient, but it can be usefull sometimes.
good luck
Sascha
-
Oct 31st, 2000, 06:17 PM
#7
Hyperactive Member
Try this:
Type TUser
username as String
haircolor as String
password as String
End Type
Dim userlist() as TUser
Dim lng As Long
Dim db As Database
Dim rs As Recordset, SQL$
Set db = OpenDatabase("C:\My Documents\mytestdb.mdb")
SQL = "SELECT username, password, haircolor FROM users where haircolor like ""blue"""
Set rs = db.OpenRecordset(SQL)
rs.MoveLast
rs.MoveFirst
Redim TUser(rs.RecordCount)
Do Until rs.EOF
TUser(lng).username = rs.username
TUser(lng).password = rs.password
TUser(lng).haircolor = rs.haircolor
lng = lng + 1
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
For lng = LBound(TUser) To UBound(TUser)
Debug.Print lng & ": " & TUser(lng).username & "," & TUser(lng).password & "," & TUser.haircolor
Next
-
Oct 31st, 2000, 06:18 PM
#8
Hyperactive Member
Gee, I wish my indenting had been included. It'll still work, though.
-
Nov 3rd, 2000, 09:59 AM
#9
Thread Starter
Addicted Member
Thanks a lot, I'll try it that way
Razzle
ICQ#: 31429438
What is the difference between a raven?
-The legs. The length is equal, especially the right one. 
-
Jan 16th, 2003, 12:54 PM
#10
Addicted Member
reverting back to Recoredset
Hie all,
By Using getString(), i am changing the representation of recordset in String. That's fine. But after converting it to a String is there a way for me to revert that particular string back to recordset again? It is just out of my curiousity. I used to do this in Java quite often. So i am wondering if it can be done in VB as well.
If there is an answer to this please post it. I am working with an example. Thank you so much,
Happy New YEar,
dave
-
Jan 16th, 2003, 02:04 PM
#11
I've got something to add.....
Originally posted by lengwai
Hie all,
By Using getString(), i am changing the representation of recordset in String. That's fine. But after converting it to a String is there a way for me to revert that particular string back to recordset again? It is just out of my curiousity. I used to do this in Java quite often. So i am wondering if it can be done in VB as well.
If there is an answer to this please post it. I am working with an example. Thank you so much,
Happy New YEar,
dave
In addition to GetString, there is also a GetRecords that will return the recordset as a two dimentional array.....
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
|