Pages

14 April 2009

Koneksi VB dengan Database Access

kode programnya seperti berikut ini :

Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public StrConnect As String
Public StrSQL As String

Public Sub Konek ()
StrConnect = “Provider=Microsoft.Jet.OleDB.4.0;Data Source=” + App.Path + “\Penjualan.mdb”
If Conn.State = adStateOpen Then
Conn.Close
Set Conn = New ADODB.Connection
Conn.Open StrConnect
Else
Conn.Open StrConnect
End If
End Sub

Atau

Public Conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public StrConnect As String
Public strSQL As String
Public Sub konek()
StrConnect = “provider=MSDASQL;DSN=admin;UID=labkom;PWD=sajada;”
‘StrConnect = “provider=microsoft.jet.oledb.4.0;data source=” + App.Path + “\labkom.mdb”
If Conn.State = adStateOpen Then
Conn.Close
Set Conn = New ADODB.Connection
Conn.Open StrConnect
Else
Conn.Open StrConnect
End If
End Sub

Keterangan : Untuk Penjualan.mdb menyesuaikan nama database yang di pakai