Public Class dbConn
Public Function Fill(ByVal cmd As SqlCommand, ByVal tname As String, ByVal dbconn As String) As DataSet
Try
cmd.Connection = New SqlConnection(dbconn)
cmd.Connection.Open()
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
If ds.Tables.Contains(tname) Then ds.Tables(tname).Clear()
da.Fill(ds, tname)
Return ds
End Using
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
Finally
cmd.Connection.Close()
cmd.Connection.Dispose()
End Try
End Function
Public Function ExecuteNonQuery(ByVal cmd As SqlCommand, ByVal dbconn As String) As Boolean
Dim ret As Boolean
Using conn As New SqlConnection(dbconn)
conn.Open()
Dim trans As SqlTransaction = conn.BeginTransaction
cmd.Connection = conn
cmd.Transaction = trans
Try
cmd.ExecuteNonQuery()
trans.Commit()
ret = True
Catch ex As Exception
MsgBox(ex.ToString)
trans.Rollback()
ret = False
Finally
conn.Close()
conn.Dispose()
End Try
End Using
Return ret
End Function
End Class