Using vb6 to retreive value from sql and place in textbox
I have been using vb6 on and off for a few years but am new to using databases in vb6. I am using the code below that I got from the net to connect which works fine however in the last statement I want to retrieve a value from the name column and place it in a textbox but I cant get it to work. Any comments would be appreciated.
'Declaring your database
Public MyDatabase As ADODB.Connection
'Tables into your database
Public MyTable1 As ADODB.Recordset
Private Sub Form_Load()
'Set your variables to nothing (just for stability)
Set MyDatabase = Nothing
Set MyTable1 = Nothing
'Connecting to your DB
Set MyDatabase = New ADODB.Connection
Set MyTable1 = New ADODB.Recordset
'Here's where you're to set all your database options
ConnectionString = "Provider=SQLOLEDB.1" _
& ";User ID=sa" _
& ";Password=theknapp1" _
& ";Initial Catalog=aTable" _
& ";Data Source=mypc\SQLEXPRESS"
'If your database is in another computer in the local network you can replace 127.0.0.1 with it's ip adress
MyTable1.CursorLocation = adUseClient
Text1.text = MyDatabase.Execute ("SELECT name FROM Table_1")
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.