|
-
Sep 20th, 2000, 09:03 AM
#1
Thread Starter
Member
Hi,
does anyone know why this doesnt work?
code:
Dim DB as Database
Dim RS as Recordset
Set DB=OpenDatabase("c:\mydata.mdb")
Set RS=DB.OpenRecordset("SELECT name FROM UserInfo WHERE Age>30")
Set Text1.DataSource = rsRecordSet
Text1.DataField = "name"
I would be very greatful to anyone who can help!!
Thanx
Sajjad
-
Sep 20th, 2000, 09:09 AM
#2
Fanatic Member
It appears that you are using DAO commands to create your recordset. The code I posted previously makes the connection to the fields presuming you are using ADO.
I am not sure how to do the same using DAO.
-
Sep 20th, 2000, 09:35 AM
#3
_______
<?>
Code:
'I suggest using sName as I think that
'Name is a VB reserved word
'
'also I have named the datacontrol Data1 not Text1
'
'this will list the names in the recordset
'
'added a listbox List1 for display purposes
'
Private Sub Command1_Click()
Dim DB As Database
Dim RS As Recordset
Set DB = OpenDatabase("c:\Mydata.mdb")
Set RS = DB.OpenRecordset("SELECT sname FROM UserInfo WHERE sAge>30")
While Not RS.EOF
List1.AddItem RS!sname
RS.MoveNext
Wend
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 21st, 2000, 02:51 AM
#4
Thread Starter
Member
Hi,
Is there anyway I can display the results in text boxes, and datagrids. Do I have to use ADO or DAO.
Thank you, for all your help
Kind Regards
Sajjad
-
Sep 21st, 2000, 03:11 AM
#5
On the data loop I normally use
While not (RS.EOF Or RS.BOF)
'Do Stuff
Wend
If there any reason why NOT to use the BOF check as well? Does the EOF always pick up the empty resultset as well or does it depend on the data source?
With SQL Server we normally cycle through the resultsets as well as through each resultset to get the data.
J.
-
Sep 21st, 2000, 03:31 AM
#6
Assuming that you do not use data bound controls...
You could show the data in a text box ...
While Not RS.EOF
text1.text = text1.text & ", " & RS(0)
RS.MoveNext
Wend
This would give you a text box with the data all in a string seperated with commas.
Or you could use a grid control. You can use the MS FlexGrid control but it is a bit crap. It can still be very usefull. (Code not for the Flex grid but you get the idea.)
Grid.MaxRows = 0
Grid.Col = 0
While Not RS.EOF
Grid.MaxRows = Grid.MaxRows + 1
Grid.Row = Grid.MaxRows
Grid.Text = RS(0)
RS.MoveNext
Wend
I also find that the ListView is very useful, works kind of like this...
Dim X as ListItem
LV.ListItems.Clear
While Not RS.EOF
SET x = LV.ListItems.AddItem RS(0)
x.SubItems(1) = RS(1)
RS.MoveNext
Wend
You can also put pictures on this and it looks like explorer, where you can view it as report or icons etc..
Hope this helps, or gives you a few ideas.
J.
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
|