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)
MsgBox("" & Query & "")
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