Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Configuration
Namespace MyDatabase
Public Class DataBase
Dim Ds As DataSet
Dim Sdr As IDataReader
Dim Cnstr As String
Dim SqlDa As SqlDataSource
Public Sub New()
Cnstr = ConfigurationManager.ConnectionStrings("Constr").ConnectionString
SqlDa = New SqlDataSource()
SqlDa.ConnectionString = Cnstr
SqlDa.ProviderName = ConfigurationManager.ConnectionStrings("Constr").ProviderName
End Sub
Public Sub GetDataset(ByVal Sql As String, ByRef Dset As DataSet)
Dim Dv As New DataView
Dim Dt As New DataTable
Try
Dset = New DataSet
SqlDa.SelectCommand = Sql
SqlDa.DataSourceMode = SqlDataSourceMode.DataSet
Dv = CType(SqlDa.Select(DataSourceSelectArguments.Empty), DataView)
Dt = Dv.ToTable
Dset.Tables.Add(Dt)
Catch ex As Exception
Finally
If Not SqlDa Is Nothing Then SqlDa.Dispose()
If Not Dv Is Nothing Then Dv.Dispose()
End Try
Public Sub Execute(ByVal Sql As String)
If Sql.ToUpper.StartsWith("INSERT") Then
SqlDa.InsertCommand = Sql
SqlDa.Insert()
ElseIf Sql.ToUpper.StartsWith("UPDATE") Then
SqlDa.UpdateCommand = Sql
SqlDa.Update()
ElseIf Sql.ToUpper.StartsWith("DELETE") Then
SqlDa.DeleteCommand = Sql
SqlDa.Delete()
End If
Public Sub Close()
If Not SqlDa Is Nothing Then SqlDa = Nothing
Public Sub GetDataReader(ByVal Sql As String, ByRef Dr As IDataReader)
SqlDa.DataSourceMode = SqlDataSourceMode.DataReader
Dr = CType(SqlDa.Select(DataSourceSelectArguments.Empty), IDataReader)
If Not Dt Is Nothing Then Dt.Dispose()
Public Function GetMax(ByVal Sql As String) As Double
Dim RecCount As Double = 0
RecCount = Dv.Count + 1
Return RecCount
End Function
Public Function GetValue(ByVal Sql As String) As Object
Dim Dt as New DataTable
Dim Result As Object = ""
Result = Dv.Table.Rows(0).Item(0)
Return Result
End Class
End Namespace