Imports System.Data.SqlClient
Imports System.Data
Public Class ConnectDB
Public Strcon As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("SIDBMSConnectDB").ConnectionString)
Public Function GetDataset(ByVal Strsql As String, _
Optional ByVal DatasetName As String = "Dataset1", _
Optional ByVal TableName As String = "Table") As DataSet
Dim DA As New SqlDataAdapter(Strsql, Strcon)
Dim DS As New DataSet(DatasetName)
Try
DA.Fill(DS, TableName)
Catch x1 As Exception
Err.Raise(60002, , x1.Message)
End Try
Return DS
End Function
Private Sub GetDataBars(ByVal PollId As String)
End Sub
Public Function ReadData(ByVal Strsql As String)
Dim command As New SqlCommand(Strsql, Strcon)
Strcon.Open()
Dim reader As SqlDataReader = command.ExecuteReader()
reader.Close()
Return reader
End Function
Public Function GetDataTable(ByVal Strsql As String, _
Optional ByVal TableName As String = "Table") As DataTable
Dim DA As New SqlDataAdapter(Strsql, Strcon)
Dim DT As New DataTable(TableName)
Try
DA.Fill(DT)
Catch x1 As Exception
Err.Raise(60002, , x1.Message)
End Try
Return DT
End Function
Public Function CreateCommand(ByVal Strsql As String) As SqlCommand
Dim cmd As New SqlCommand(Strsql)
Return cmd
End Function
Public Function Execute(ByVal Strsql As String) As Integer
Dim cmd As New SqlCommand(Strsql)
Dim X As Integer = Me.Execute(cmd)
Return X
End Function
Public Function Execute(ByRef Cmd As SqlCommand) As Integer
Dim Cn As SqlConnection = Strcon
Cmd.Connection = Cn
Dim X As Integer
Try
Cn.Open()
X = Cmd.ExecuteNonQuery()
Catch
X = -1
Finally
Strcon.Close()
End Try
Return X
End Function
End Class