001.
Imports
System.Data
002.
Imports
System.Data.OleDb
003.
Imports
System.Configuration
004.
Public
Class
clsDatabase
005.
Private
objConn
As
OleDbConnection
006.
Private
objCmd
As
OleDbCommand
007.
Private
Trans
As
OleDbTransaction
008.
Private
strConnString
As
String
009.
010.
Public
Sub
New
()
011.
strConnString = System.Configuration.ConfigurationSettings.AppSettings(
"ConnectionString"
)
012.
End
Sub
013.
014.
Public
Function
QueryDataReader(
ByVal
strSQL
As
String
)
As
OleDbDataReader
015.
Dim
dtReader
As
OleDbDataReader
016.
objConn =
New
OleDbConnection
017.
With
objConn
018.
.ConnectionString = strConnString
019.
.Open()
020.
End
With
021.
objCmd =
New
OleDbCommand(strSQL, objConn)
022.
dtReader = objCmd.ExecuteReader()
023.
Return
dtReader
024.
End
Function
025.
026.
Public
Function
QueryDataSet(
ByVal
strSQL
As
String
)
As
DataSet
027.
Dim
ds
As
New
DataSet
028.
Dim
dtAdapter
As
New
OleDbDataAdapter
029.
objConn =
New
OleDbConnection
030.
With
objConn
031.
.ConnectionString = strConnString
032.
.Open()
033.
End
With
034.
objCmd =
New
OleDbCommand
035.
With
objCmd
036.
.Connection = objConn
037.
.CommandText = strSQL
038.
.CommandType = CommandType.Text
039.
End
With
040.
dtAdapter.SelectCommand = objCmd
041.
dtAdapter.Fill(ds)
042.
Return
ds
043.
End
Function
044.
045.
Public
Function
QueryDataTable(
ByVal
strSQL
As
String
)
As
DataTable
046.
Dim
dtAdapter
As
OleDbDataAdapter
047.
Dim
dt
As
New
DataTable
048.
objConn =
New
OleDbConnection
049.
With
objConn
050.
.ConnectionString = strConnString
051.
.Open()
052.
End
With
053.
dtAdapter =
New
OleDbDataAdapter(strSQL, objConn)
054.
dtAdapter.Fill(dt)
055.
Return
dt
056.
End
Function
057.
058.
Public
Function
QueryExecuteNonQuery(
ByVal
strSQL
As
String
)
As
Boolean
059.
objConn =
New
OleDbConnection
060.
With
objConn
061.
.ConnectionString = strConnString
062.
.Open()
063.
End
With
064.
Try
065.
objCmd =
New
OleDbCommand
066.
With
objCmd
067.
.Connection = objConn
068.
.CommandType = CommandType.Text
069.
.CommandText = strSQL
070.
End
With
071.
objCmd.ExecuteNonQuery()
072.
Return
True
073.
Catch
ex
As
Exception
074.
Return
False
075.
End
Try
076.
End
Function
077.
078.
Public
Function
QueryExecuteScalar(
ByVal
strSQL
As
String
)
As
Object
079.
Dim
obj
As
Object
080.
objConn =
New
OleDbConnection
081.
With
objConn
082.
.ConnectionString = strConnString
083.
.Open()
084.
End
With
085.
Try
086.
objCmd =
New
OleDbCommand
087.
With
objCmd
088.
.Connection = objConn
089.
.CommandType = CommandType.Text
090.
.CommandText = strSQL
091.
End
With
092.
obj = objCmd.ExecuteScalar()
093.
Return
obj
094.
Catch
ex
As
Exception
095.
Return
Nothing
096.
End
Try
097.
End
Function
098.
099.
100.
101.
Public
Function
TransStart()
102.
objConn =
New
OleDbConnection
103.
With
objConn
104.
.ConnectionString = strConnString
105.
.Open()
106.
End
With
107.
Trans = objConn.BeginTransaction(IsolationLevel.ReadCommitted)
108.
End
Function
109.
110.
Public
Function
TransExecute(
ByVal
strSQL
As
String
)
As
Boolean
111.
objCmd =
New
OleDbCommand
112.
With
objCmd
113.
.Connection = objConn
114.
.Transaction = Trans
115.
.CommandType = CommandType.Text
116.
.CommandText = strSQL
117.
End
With
118.
objCmd.ExecuteNonQuery()
119.
End
Function
120.
121.
Public
Function
TransRollBack()
122.
Trans.Rollback()
123.
End
Function
124.
125.
Public
Function
TransCommit()
126.
Trans.Commit()
127.
End
Function
128.
129.
Public
Sub
Close()
130.
objConn.Close()
131.
objConn =
Nothing
132.
End
Sub
133.
134.
End
Class