代码如下:
Imports System.Data
Imports System.Data.OleDb
Public Class Conn
Public Sub New()
End Sub
Public ReadOnly Property Connection() As OleDbConnection
Get
Dim conn As New OleDbConnection(New Config().ConnStr)
conn.Open()
Return conn
End Get
End Property
Public ReadOnly Property ReadSQL(ByVal SQL As String, ByVal Values As Array) As OleDbDataReader
Get
Dim cmd As New OleDbCommand(SQL, Connection())
For i = 0 To Values.GetUpperBound(0)
cmd.Parameters.Add(New OleDbParameter("@p" & i + 1, Values(i)))
Next
Return cmd.ExecuteReader()
End Get
End Property
Public ReadOnly Property ExecSQL(ByVal SQL As String, ByVal Values As Array) As Integer
Get
Dim exec As New OleDbCommand(SQL, Connection())
For i = 0 To Values.GetUpperBound(0)
exec.Parameters.Add(New OleDbParameter("@p" & i + 1, Values(i)))
Next
Return exec.ExecuteNonQuery()
End Get
End Property
Public ReadOnly Property CountSQL(ByVal Table As String, ByVal Where As String, ByVal Values As Array) As Integer
Get
Dim exec As New OleDbCommand("Select count(*) From [" & Table & "] Where " & Where, Connection())
For i = 0 To Values.GetUpperBound(0)
exec.Parameters.Add(New OleDbParameter("@p" & i + 1, Values(i)))
Next
Return exec.ExecuteScalar()
End Get
End Property
End Class
VS2010编译通过。
发表评论