Imports System.Data.OleDb
Imports System.Configuration
Imports System.data
Public Class Connect
'声明联接字符串
Private connectionString As String
Private myConnection As OleDbConnection
Private myCommand As OleDbCommand
Private myAdpt As OleDbDataAdapter
Public Sub New(ByVal config_string As String)
connectionString = System.Configuration.ConfigurationManager.AppSettings(config_string) + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings("data"))
myConnection = New OleDbConnection(connectionString)
End Sub
Public Function QueryForTable(ByVal qs As String) As DataTable
Dim dt As New DataTable("temp")
myAdpt = New OleDbDataAdapter(qs, myConnection)
myAdpt.Fill(dt)
Return dt
End Function
Public Function QueryForSet(ByVal qs As String) As DataSet
Dim dt As New DataSet()
myAdpt = New OleDbDataAdapter(qs, myConnection)
myAdpt.Fill(dt)
Return dt
End Function
Public Function QueryForReader(ByVal qs As String, ByVal bAddSpaceItem As Boolean) As ArrayList
Dim thisReader As OleDbDataReader
Dim values As ArrayList = New ArrayList
myConnection.Open()
myCommand = myConnection.CreateCommand()
myCommand.CommandText = qs
'打开数据连接
thisReader = myCommand.ExecuteReader()
If bAddSpaceItem = True Then
values.Add("")
End If
Do While thisReader.Read
values.Add(Trim$(thisReader(0)))
Loop
'关闭数据连接
thisReader.Close()
myConnection.Close()
Return values
End Function
End Class