Connection VB6.0 to MS SQL SERVER 2000

Saturday, August 22, 2009

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.

About This Blog

Check Page Rank of any web site pages instantly:
This free page rank checking tool is powered by Page Rank Checker service

Visitor

Blogging by 4visited  © 2015

Back to TOP