Aetia
asked on
Retrive a random record from database
Hey!
I'd like to retrive random record from my MS Access database. It would work like if I click on "Button2" it would show me random record from column "UserAgent" in "TextBox1".
Code I currently have is like this:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
xConn = New sqlConn
xConn.connectMe("SELECT * UserAgent FROM UserAgents ORDER BY RAND() LIMIT 1")
For iCounter = 0 To xConn.getData.Count - 1
TextBox1.Text = (xConn.dataReturned.Item(i Counter))
Next
xConn.OLEConn.Close()
End Sub
It doesn't work... Anybody got ideas?
I'd like to retrive random record from my MS Access database. It would work like if I click on "Button2" it would show me random record from column "UserAgent" in "TextBox1".
Code I currently have is like this:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
xConn = New sqlConn
xConn.connectMe("SELECT * UserAgent FROM UserAgents ORDER BY RAND() LIMIT 1")
For iCounter = 0 To xConn.getData.Count - 1
TextBox1.Text = (xConn.dataReturned.Item(i
Next
xConn.OLEConn.Close()
End Sub
It doesn't work... Anybody got ideas?
ASKER
I am newbie... :)
I put tgether all i've found. Something from here something from there...
It seems that it connects to database correctly... it gives me following error:
Syntax error (missing operator) in query expression '*UserAgent'.
I put tgether all i've found. Something from here something from there...
It seems that it connects to database correctly... it gives me following error:
Syntax error (missing operator) in query expression '*UserAgent'.
What are you attempting to do with this:
SELECT * UserAgent FROM UserAgents
as Select * will return MULTIPLE columns (all of the columns in the record), and you cannot assign a Alias (UserAgent) to MULTIPLE values.
Try this:
SELECT * FROM UserAgents ...
AW
SELECT * UserAgent FROM UserAgents
as Select * will return MULTIPLE columns (all of the columns in the record), and you cannot assign a Alias (UserAgent) to MULTIPLE values.
Try this:
SELECT * FROM UserAgents ...
AW
ASKER
if I click on "Button2" it would show me random record from column "UserAgent" in "TextBox1".
or
SELECT UserAgent FROM UserAgents
SELECT UserAgent FROM UserAgents
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As far this should be right now
xConn = New sqlConn
xConn = New sqlConn
xConn.connectMe("SELECT UserAgent FROM UserAgents")
What next? How can I display random result from database in "TextBox1"?
xConn = New sqlConn
xConn = New sqlConn
xConn.connectMe("SELECT UserAgent FROM UserAgents")
What next? How can I display random result from database in "TextBox1"?
ASKER
OK! I got it almost working myselft.
-Baan