Imports System.Data.SqlClient
Public Class SQLcontrol
Private SQLcon As New SqlConnection With {.ConnectionString = "Data Source=ANUE-NB\SQLEXPRESS;Initial Catalog=chaiwat;Integrated Security=True"}
Private SQLcmd As SqlCommand
Public SQLDA As SqlDataAdapter
Public SQLDS As DataSet
Public Function HasConnection() As Boolean
Try
SQLcon.Open()
SQLcon.Close()
Return True
Catch ex As Exception 'HasConnection-->Check Connection
MsgBox(ex.Message)
End Try
Return False
End Function
Public Sub RunQuery(ByVal Query As String)
Try
SQLcon.Open()
SQLcmd = New SqlCommand(Query, SQLcon)
SQLDA = New SqlDataAdapter(SQLcmd)
SQLDS = New DataSet
SQLDA.Fill(SQLDS)
Catch ex As Exception
MsgBox(ex.Message)
If SQLcon.State = ConnectionState.Open Then
SQLcon.Close()
End If
End Try
End Sub
End Class
Public Class Form1
Public SQl As SQLcontrol
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SQl.RunQuery("SELECT * FROM member ")
SQl.SQLDA.Fill(SQl.SQLDS, "Emp")
DataGridView1.DataSource = SQl.SQLDS.Tables(0)
End Sub
End Class
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim SQLcon As New SqlConnection With {.ConnectionString = "Data Source=ANUE-NB\SQLEXPRESS;Initial Catalog=chaiwat;Integrated Security=True"}
Dim SQLcmd As SqlCommand
Dim SQLDA As SqlDataAdapter
Dim SQLDS As DataSet
Dim Query = "SELECT * FROM member "
SQLcon.Open()
SQLcmd = New SqlCommand(Query, SQLcon)
MsgBox("" & Query & "")
SQLDA = New SqlDataAdapter(SQLcmd)
SQLDS = New DataSet
SQLDA.Fill(SQLDS)
SQLDA.Fill(SQLDS, "Emp")
DataGridView1.DataSource = SQLDS.Tables("EMP")
End Sub
End Class