Koneksi MySQL with VB6 (ADODB)

Project Code :
Dim CnMySQL As ADODB.Connection
Dim Rs As New ADODB.Recordset

Private Sub Koneksi()
Set CnMySQL = New ADODB.Connection
CnMySQL.ConnectionString = “DRIVER={MySQL ODBC 3.51 Driver};SERVER=yourserver;UID=root;PWD=yourpasword;DATABASE=yourdatabase”
End Sub

Private Sub Command1_Click() ‘open koneksi
If CnMySQL.State = adStateOpen Then
MsgBox “Open Connection”, vbInformation, “Koneksi”
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
MsgBox “Close Connection”, vbInformation, “Koneksi”
End If

End Sub

Private Sub Command2_Click() ‘tutup koneksi
If CnMySQL.State = adStateOpen Then
End If
Unload Me
End Sub

Private Sub Command3_Click() ‘retrieve data
If Rs.State = adStateOpen Then Rs.Close
Rs.Open “Select * from MstCustomer”, CnMySQL, adOpenKeyset, adLockReadOnly
Set vsf.DataSource = Rs
End Sub

Private Sub Command4_Click() ‘tambah data
CnMySQL.Execute “Insert Into MstCustomer (Fcode,Fname) values (‘gue’,’Tes Aja’)”
End Sub

Private Sub Command5_Click()
CnMySQL.Execute “Delete From MstCustomer Where Fcode=’gue'”
End Sub

Private Sub Form_Load() ‘hapus data
vsf.Rows = 2
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
End Sub

Object :
1. Form
3. VsFlexGrid
4. CommandButton


About alkahfi

Bekerja di bidang IT-MIS di sebuah perusahaan Optik di Medan, sebagai Software Enginer.

Posted on April 23, 2008, in Programming and tagged , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: