First you have to make a project and put this code in a Modul
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Public Rsg As ADODB.Recordset
Public con As ADODB.Connection
Sub ATCONN()
'On Error Resume Next
LoginName = "sa"
LoginPassword = "2583094"
DBNm = User.Text3
ServerName = User.Text6
Set con = New ADODB.Connection
If con.State = 1 Then con.Close
con.Open ("uid=" & LoginName & ";pwd=" & LoginPassword & ";server=" & ServerName & ";" & "driver={SQL Server};database=" & DBNm & ";")
If con.State <> adStateOpen Then
Call Errmsg("Connection Error, Server is not exist")
End
End If
Set Rsg = New ADODB.Recordset
If Rsg.State = 1 Then Rsg.Close
With Rsg
.ActiveConnection = con
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
Rsg.Open strSQL
End With
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
in Project > Reference select microsoft activex data objects 2.5 library
now from any where you can connect to you sql data base like this
strsql="select * from TABLE"
atconn
that's all
0 التعليقات:
إرسال تعليق