gcw
asked on
Simple SQL Question
Does someone have some code that would allow me to access a table in SQL and pass the information found into a textbox??? I need instructions on how to connect and perform the query.. I am very new to SQL.. I am however a fast learner. Any help would be appreciated
ASKER
I need to access a SQL Table not an access Database
Are you using RDO or DAO?
ASKER
DAO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how do I get the information from the database and place into a textbox then? I will give more points...
Dim MyRec as Recordset
Set MyRec = conPubs.OpenRecordset( "SELECT * FROM MyTable", dbOpenSnapshot)
if not Myrec.eof then
Text1 = MyRec!MyField & vbnullstring
end if
Set MyRec = conPubs.OpenRecordset( "SELECT * FROM MyTable", dbOpenSnapshot)
if not Myrec.eof then
Text1 = MyRec!MyField & vbnullstring
end if
for instance.. flop a listbox on a form.
in the form_click event.. do this..
it will populate the listbox with the authors'last name from the authors table in your SQL Server Database..<assuming you didnt take it out>
Sub Form_click()
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim MyRec As Recordset
'assumes you have a Pubs DSN created for yourself
Set wrkODBC = CreateWorkspace("MySQLWork space", _
"sa", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("", dbDriverPrompt, , _
"ODBC;DATABASE=Pubs;UID=sa ;PWD=;DSN= Pubs;")
Set MyRec = conPubs.OpenRecordset("SEL ECT au_lname FROM Authors", dbOpenSnapshot)
Do While Not MyRec.EOF
List1.AddItem MyRec!au_lname & vbNullString
MyRec.MoveNext
Loop
End Sub
in the form_click event.. do this..
it will populate the listbox with the authors'last name from the authors table in your SQL Server Database..<assuming you didnt take it out>
Sub Form_click()
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim MyRec As Recordset
'assumes you have a Pubs DSN created for yourself
Set wrkODBC = CreateWorkspace("MySQLWork
"sa", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("",
"ODBC;DATABASE=Pubs;UID=sa
Set MyRec = conPubs.OpenRecordset("SEL
Do While Not MyRec.EOF
List1.AddItem MyRec!au_lname & vbNullString
MyRec.MoveNext
Loop
End Sub
ASKER
thanks! this helps alot :)
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
' Open Database object from saved Microsoft Jet database
' for exclusive use.
Set dbsNorthwind = wrkJet.OpenDatabase("North
True)
' Create a recordset to get all Employees
Set rstTemp = dbsNorthwind.OpenRecordset
'Set the value of the textbox to Employee name
Textbox1.text = rstTemp("field_name")
If you need some more explanation, ask for it before grading the question.