Ricky Andes || Selamat malam agan - agan ^_^
Pada kesempatan kali ini kita akan membahas bagaimana cara membuat class pada visual bassic 2008. tidak perlu susah susah silahkan agan - agan copy coding yang telah ane siapkan di bawah ini dan insert ke program agan ok. hehehe cheki doooootttt :D
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Imports System.Data
Public Class Cskader
Protected tblpeng As New DataTable
Protected SQL As String
Protected cn As OleDbConnection
Protected cmd As OleDbCommand
Protected Da As OleDbDataAdapter
Protected ds As DataSet
Protected dt As DataTable
Public Function openconn() As Boolean
cn = New OleDbConnection("provider=microsoft.ACE.OLEDB.12.0;Data source=" & _
Application.StartupPath & "\komunitas.mdb;")
cn.Open()
If cn.State <> ConnectionState.Open Then
Return False
Else
Return True
End If
End Function
Public Sub closeconn()
If Not IsNothing(cn) Then
cn.Close()
cn = Nothing
End If
End Sub
Public Function ExecuteQuery(ByVal Query As String) As DataTable
If Not openconn() Then
MsgBox("Koneksi gagal ...!!!", MsgBoxStyle.Critical, "Acces Failid")
Return Nothing
Exit Function
End If
cmd = New OleDbCommand(Query, cn)
Da = New OleDbDataAdapter
Da.SelectCommand = cmd
ds = New Data.DataSet
Da.Fill(ds)
dt = ds.Tables(0)
Return dt
dt = Nothing
ds = Nothing
Da = Nothing
cmd = Nothing
closeconn()
End Function
Public Sub ExecuteNonQuery(ByVal Query As String)
If Not openconn() Then
MsgBox("Koneksi gagal...!!!", MsgBoxStyle.Critical, "Access falid")
Exit Sub
End If
cmd = New OleDbCommand
cmd.Connection = cn
cmd.CommandText = Query
cmd.ExecuteNonQuery()
cmd = Nothing
closeconn()
End Sub
End Class
Selamatt mencoba hhehehehe ^_^
Friday, June 13, 2014
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment