Below is a sample class, that should do the job
If you need a connection string sample please reply with a request
hth,
Samuel
Public Class clsDataSQL
Public Shared Function GetConnectObj() As SqlClient.SqlConnection
Return New SqlClient.SqlConnection(objProgGlobals.ConnectionString)'The
connection string should be assigned
End Function
'Return a dataTable that was filled by the Adaptor.Fill method
Public Shared Function FillData(ByVal sSQL As String) As DataTable
Dim objDataAdapter As New System.Data.SqlClient.SqlDataAdapter(sSQL,
GetConnectObj)
Dim ObjTable As New DataTable("")
Try
objDataAdapter.Fill(ObjTable)
Catch Ex As System.data.SqlClient.SqlException
'Log the error
clsErrorLog.Log(Ex)
MsgBox(Ex.Message)
End Try
Return ObjTable
End Function
'Returns the ID of the new record
Shared Function DataSetAdaptor(ByVal sCommandText As String, _
ByRef iErrorNum As Integer, _
ByRef sErrorDesc As String, _
ByVal bNotLog As Boolean, _
ByVal bNotifyError As Boolean) As Integer
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim objReader As System.Data.SqlClient.SqlDataReader
With objCmd
.Connection = GetConnectObj()
.CommandText = sCommandText
.CommandType = CommandType.Text
End With
Try
objCmd.Connection.Open()
Catch myException As System.Exception
If myException.GetType.ToString =
"System.Data.SqlClient.SqlException" Then
iErrorNum = CType(myException,
System.Data.SqlClient.SqlException).Number
Exit Function
End If
If Not bNotLog Then
clsErrorLog.Log(myException)
iErrorNum = -1
sErrorDesc = myException.Message
End If
'Notify the error to the user
If bNotifyError Then
MsgBox(myException.Message)
End If
End Try
If objCmd.Connection.State = ConnectionState.Open Then
Try
objReader =
objCmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While objReader.Read()
DataSetAdaptor = objReader(0)
Loop
objReader.Close()
Catch myException As System.Data.SqlClient.SqlException
If Not bNotLog Then
'Log the error
clsErrorLog.Log(myException)
End If
iErrorNum = myException.Number
'Notify the error to the user
If bNotifyError Then
MsgBox(myException.Message)
End If
Try
'Close the object reader that will cause the connection
to close
objReader.Close()
Catch
End Try
End Try
objCmd.Connection.Close()
End If
End Function
End Class