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”
CnMySQL.Open
End Sub
Private Sub Command1_Click() ‘open koneksi
Koneksi
If CnMySQL.State = adStateOpen Then
MsgBox “Open Connection”, vbInformation, “Koneksi”
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Else
MsgBox “Close Connection”, vbInformation, “Koneksi”
End If
End Sub
Private Sub Command2_Click() ‘tutup koneksi
If CnMySQL.State = adStateOpen Then
CnMySQL.Close
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
vsf.Refresh
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
2. MS ADODB
3. VsFlexGrid
4. CommandButton
RSS Feed
