***** Ini Coding Untuk Di Classnya Misal Nama Classnya POSCls
Dim RsKu As ADODB.Recordset
Dim ConOut As ADODB.Connection
Sub Class_Initialize()
Set RsKu = New ADODB.Recordset
End Sub
Sub Class_Terminate()
On Error Resume Next
RsKu.Close
Set RsKu = Nothing
ConOut.Close
Set ConOut = Nothing
End Sub
'Function Untuk Membuka koneksi
Public Function Buka_kon(ByVal Kon As String) As Boolean
On Error GoTo err_kon
Set ConOut = New ADODB.Connection
ConOut.Open Kon
Buka_kon = True
Exit Function
err_kon:
Buka_kon = False
Exit Function
End Function
'Fungis Untuk Mencari Barang
Public Function Cari_brg(ByVal kdbrg As String) As Boolean
Set RsKu = ConOut.Execute("select * from mbarang where kd_brg='" & kdbrg
& "'")
With RsKu
If Not (.EOF Or .BOF) Then
Cari_brg = True
Else
Cari_brg = False
End If
End With
End Function
'Properti Untuk mengambil Nama Barang
Public Property Get Nm_brg()
If IsNull(RsKu!Nm_brg) = False Then
Nm_brg = RsKu!Nm_brg
Else
Nm_brg = ""
End If
End Property
****** Ini Coding Untuk di Formnya
Dim MyCls as POSCls
Dim Cn_Str as string
Private Sub Form1_load()
'Misalkan database kita SLQServer, database=Inventory
Cn_str = "Provider=SQLOLEDB;data
source=localhost;initialcatalog=sale_in;trusted_connection=Yes;"
set Mycls=new POSCLS
If Not si.Buka_kon(Cn_Str) Then
MsgBox "Koneksi Ke Server Gagal"
Exit Sub
End If
end sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
if Mycls.Cari_brg(text1.text) then
text2.text=Mycls.Nm_brg
else
Msgbox "Nama Barang Tidak Ada !!!",vbInformation
end if
End Sub
Segitu Dulu Semoga bisa dipahami kl masih kurang paham bisa hubungi ane
Fahrul Rizal <[EMAIL PROTECTED]> wrote:
halo gmana kbarnya semua
ane mo tanya nih
klo koneksi melalui module or class
itu da perlu refres ga yah
biar waktu saat ane pindah database
dari acces ke sql itu hanya merubah di module or classnya aja
ga perlu merubah semua koneksi nya yang da ada.......?
thanks
__________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121
[Non-text portions of this message have been removed]
---------------------------------
Have a burning question? Go to Yahoo! Answers and get answers from real people
who know.
[Non-text portions of this message have been removed]