This is a simple code to connect vb6.0 with sql server, learn more...
First, make sure that your computer have been installed vb6.0 and ms SQL SERVER. Make a new project in vb6.0, Select Menu (Project => Reference) and check the Microsoft ActiveX Data Objects library (Sample : Microsoft ActiveX Data Objects 2.5 library) then click OK button.
Second, add a module (Select menu Project => Add Module) and paste code bellow :
Public Conn As New ADODB.Connection
Public Rec As New ADODB.Recordset 'berfungsi sebagai variabel penyimpan sementara
Public SQL As String ' variabel untuk menampung kode atau query sql
Public Server,Database,UserName,Password as String
Public Sub OpenConn()
On Error GoTo Handle
Set Conn = New Connection
Set Rec = New Recordset
With Conn
.ConnectionString = "Data Source=" & Server & ";Initial Catalog=" & Database & ";User Id=" & UserName & ";Password=" & Password
.Provider = "SQLOLEDB"
.Open
End With
Rec.Open SQL, Conn
Handle:
Msgbox"Any Problems !"
End Sub
Public Sub CloseConn()
Conn.Close
Set Conn = Nothing
End Sub
Try and enjoy it....
Any problems ? comment this article.
0 komentar:
Post a Comment
Kritik dan saran yang membangun kami harapkan!