- Pertama buat sebuah modul dan masukan script dibawah ini :
Imports System.Data.SqlClient
Imports System.Data.Sql
Module Module1
Public con As SqlConnection
Public cmd As SqlCommand
Public ds As DataSet
Public da As SqlDataAdapter
Public rd As SqlDataReader
Public db As String
Public Sub koneksi()
db = "Integrated Security=SSPI; Persist Security Info=True;Initial Catalog=db_coba; Data Source=USER-PC\SQLEXPRESS"
con = New SqlConnection(db)
Try
If con.State = ConnectionState.Closed Then
con.Open()
MsgBox("Koneksi Ke Database Berhasil", MsgBoxStyle.Information, "Informasi")
End If
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "Error")
End Try
End Sub
Public Function SQLTable(ByVal Source As String) As DataTable
Try
Dim adp As New SqlClient.SqlDataAdapter(Source, con)
Dim DT As New DataTable
adp.Fill(DT)
SQLTable = DT
Catch ex As SqlClient.SqlException
MsgBox(ex.Message)
SQLTable = Nothing
End Try
End Function
End Module
Oke sekian dan selamat mencoba terimaksih..
Imports System.Data.Sql
Module Module1
Public con As SqlConnection
Public cmd As SqlCommand
Public ds As DataSet
Public da As SqlDataAdapter
Public rd As SqlDataReader
Public db As String
Public Sub koneksi()
db = "Integrated Security=SSPI; Persist Security Info=True;Initial Catalog=db_coba; Data Source=USER-PC\SQLEXPRESS"
con = New SqlConnection(db)
Try
If con.State = ConnectionState.Closed Then
con.Open()
MsgBox("Koneksi Ke Database Berhasil", MsgBoxStyle.Information, "Informasi")
End If
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "Error")
End Try
End Sub
Public Function SQLTable(ByVal Source As String) As DataTable
Try
Dim adp As New SqlClient.SqlDataAdapter(Source, con)
Dim DT As New DataTable
adp.Fill(DT)
SQLTable = DT
Catch ex As SqlClient.SqlException
MsgBox(ex.Message)
SQLTable = Nothing
End Try
End Function
End Module
0 comments: