Hi, i am having problems connecting to a sql database, using
VB to connect to dtabase, can anyone help me.
The code i have is;
Option Explicit
Dim conn As New ADODB.Connection 'This declares the name of the connection
Dim rs As New ADODB.Recordset 'This declares the name of the recordset
Dim sSQL As String 'Variable used to open the recordset
Private Sub Command1_Click()
Dim dbtest As String 'Connection string variable
Dim dbstate As Long
dbtest = "Provider=sqloledb;DRIVER={SQLServer};SERVER=serve rname;DATABASE=database name;UID=******;PASSWORD=*******" 'Connection String"
conn.Open dbtest
dbstate = conn.State
sSQL = "Select * from stafftb"
rs.Open sSQL, conn 'Open the records Staff_Name
While Not (rs.EOF) 'Until the end of the recordset is reached
MsgBox rs(0) 'displays the first field of the current record
rs.MoveNext
Wend
rs.Close
conn.Close
Set rs = Nothing
End Sub
Thanks