Coding Untuk Koneksi Database VB 6.0

Document Sample
Coding Untuk Koneksi Database VB 6.0 Powered By Docstoc
					;Aplikasi Kas Kecil Pada KOPERASI KARYAWAN PT. YKK AP INDONESIA
;Author: Deni Cahyadi
;Create: 01 Mar 2008

;Update:

Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName As String, ByVal lpNewFileName As String, ByVal
bFailIfExists As Long) As Long
Public Declare Function CreateDirectory Lib "kernel32" Alias
"CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As
Long) As Long

Public Koneksi As New ADODB.Connection 'Mendeklarasikan Koneksi dengan
ADODC Connection
Public Koneksi1 As New ADODB.Connection
Public Rs_CashOut As New ADODB.Recordset 'Mendeklarasikan Recordset yang
akan digunakan
Public Rs_CashIn As New ADODB.Recordset

Public Rs_LisCashOut As New ADODB.Recordset
Public Rs_LisCashIn As New ADODB.Recordset

Public Rs_DataUser As New ADODB.Recordset
Public Rs_ViewIn As New ADODB.Recordset
Public Rs_ViewInDetail As New ADODB.Recordset

Public Rs_ViewOUT As New ADODB.Recordset

Public SQLInsert As String
Public SQLInsertLis As String
Public SQL As String

Public   SQLViewIn As String
Public   SQLViewOut As String
Public   SQLUpdate As String
Public   SQLUpdateLis As String

Public   x As String, y As String, z As String
Public   b, b2, t, t2, c As String
Public   i As Integer
Public   d As Long
Public   tbh As Boolean

Public   Const   GWL_EXSTYLE = (-20)
Public   Const   WS_EX_TRANSPARENT = &H20&
Public   Const   SWP_FRAMECHANGED = &H20
Public   Const   SWP_NOMOVE = &H2
Public   Const   SWP_NOSIZE = &H1
Public   Const   SWP_SHOWME = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
Public   Const   HWND_NOTOPMOST = -2

Global VLogOut As Boolean
Global VUserPassword As String
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal
hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As
Long, ByVal cy As Long, ByVal wFlags As Long) As Long


Sub BukaData()
    Set Koneksi = New ADODB.Connection

    Koneksi.CursorLocation = adUseClient 'Memilih lokasi kursor diserver
atau di client

;Berikut ini syntax untuk koneksi database dengan menggunakan Ms. Acces
2003
'    Koneksi.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
App.Path & "\KOPVOUCER.mdb;Persist Security Info=False"

;Berikut ini syntax untuk koneksi database dengan menggunakan Ms. SQL
SERVER
    'Berikut ini kode program untuk membuka tabel atau recordset dengan
type kursor
    'OpenDynamic dan type Penguncian Pessimistic

'    Set Koneksi = New ADODB.Connection
'    Koneksi.CursorLocation = adUseClient

'    Koneksi = "Driver={SQL Server}; " _
'        & " SERVER=KOPERASI-04; DATABASE=KOPVOUCER"

'    Koneksi.Open "Provider=SQLOLEDB; Data Source=192.168.10.4 ; " & _
'                 "Persist Security Info=FALSE; " & _
'                 "Initial Catalog=KOPVOUCER; " & _
'                 "User Id=cahya; Password=cahya;"

    Koneksi.Provider = "SQLOLEDB.1;server=DBSERVER;User
ID=ss;password=ss;Initial Catalog=KOPVOUCER"

    If Koneksi.State = adStateOpen Then
       Koneksi.Close
       Set Koneksi = New ADODB.Connection
           Koneksi.Open
    Else
           Koneksi.Open
    End If


    Set Rs_CashOut = New ADODB.Recordset
        Rs_CashOut.Open "SELECT * FROM Cash_Out ORDER BY No_Voucher",
Koneksi, adOpenDynamic, adLockPessimistic

    Set Rs_LisCashOut = New ADODB.Recordset
        Rs_LisCashOut.Open "SELECT * FROM Lis_CashOut", Koneksi,
adOpenDynamic, adLockPessimistic

    Set Rs_ViewOUT = New ADODB.Recordset
    SQLViewOut = "SELECT Cash_Out.Tanggal,Cash_Out.No_Voucher, " _
                 & "Lis_CashOut.Keterangan," _
                 & "Lis_CashOut.Jumlah FROM Cash_Out,Lis_CashOut " _
                 & "WHERE Cash_Out.No_Voucher=Lis_CashOut.No_Voucher"
    Set Rs_ViewOUT = Koneksi.Execute(SQLViewOut)

    Set Rs_CashIn = New ADODB.Recordset
        Rs_CashIn.Open "SELECT * FROM Cash_In", Koneksi, adOpenDynamic,
adLockPessimistic

    Set Rs_LisCashIn = New ADODB.Recordset
        Rs_LisCashIn.Open "SELECT * FROM Lis_CashIn", Koneksi,
adOpenDynamic, adLockPessimistic

    Set Rs_ViewIn = New ADODB.Recordset
    SQLViewIn = "SELECT Cash_In.Tanggal,Cash_In.No_Voucher, " _
                 & "Lis_CashIn.Keterangan," _
                 & "Lis_CashIn.Jumlah FROM Cash_In,Lis_CashIn " _
                 & "WHERE Cash_In.No_Voucher=Lis_CashIn.No_Voucher"
    Set Rs_ViewIn = Koneksi.Execute(SQLViewIn)

End Sub

Sub BukaData1()
 Set Koneksi1 = New ADODB.Connection
     Koneksi1.CursorLocation = adUseClient 'Memilih lokasi kursor
diserver atau di client

    'Membuka Database Test.mdb dengan Provider MS.Acces 2003
     Koneksi1.Open "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source =" &
App.Path & "\KOPVOUCER1.mdb;Jet OLEDB:Database Password=;"

     Rs_DataUser.Open "DataUser", Koneksi1, adOpenDynamic,
adLockPessimistic
End Sub

Sub Tutup()
    Koneksi1.Close 'Menutup koneksi database Master Anggota.mdb
End Sub
Sub Main()
    Frm_Login.Show
End Sub

Public Sub BackUP(CDBox As CommonDialog)
    CDBox.Filter = "Database File (*.mdb)|*.mdb"
    CDBox.DialogTitle = "Pilih Database"
    CDBox.ShowSave
    CreateDirectory "C:\Program Files\dRCOMP\", ByVal &H0
    If CDBox.FileName = "" Then Exit Sub
       CopyFile CDBox.FileName, "C:\Program Files\dRCOMP\" +
CDBox.FileTitle, 0
End Sub

				
DOCUMENT INFO
Shared By:
Tags:
Stats:
views:730
posted:6/16/2011
language:Indonesian
pages:4
Description: Berikut adalah syntax untuk mode koneksi database dengan menggunakan VB 6.0