Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class DataBase
''' <summary>
''' Returns a DataTable from MS Access database.
''' </summary>
''' <param name="SQLQuery">SQL query.</param>
''' <param name="PathToMDB">Path to database file.</param>
''' <returns>The DataTable object.</returns>
Public Shared Function GetDataTableOleDb(ByVal SQLQuery As String, ByVal PathToMDB As String) As DataTable
Dim conn As New OleDbConnection()
Dim myAdapter As New OleDbDataAdapter()
Dim myDataTable As New DataTable()
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
System.Web.HttpContext.Current.Server.MapPath(PathToMDB)
myAdapter.SelectCommand = New OleDbCommand(SQLQuery, conn)
conn.Open()
Try
myAdapter.Fill(myDataTable)
Finally
myAdapter.Dispose()
conn.Close()
conn = Nothing
End Try
Return myDataTable
End Function
''' <summary>
''' Returns a DataTable from MS SQL Server.
''' </summary>
''' <param name="query">SQL query.</param>
''' <returns>The DataTable object.</returns>
Public Shared Function GetDataTableSql(ByVal query As String) As DataTable
Dim conn As New SqlConnection()
Dim myAdapter As New SqlDataAdapter()
Dim myDataTable As New DataTable()
conn.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=dbStructure;Data Source=LOCAL_SERVER"
myAdapter.SelectCommand = New SqlCommand(query, conn)
Try
conn.Open()
myAdapter.Fill(myDataTable)
Finally
myAdapter.Dispose()
conn.Close()
conn = Nothing
End Try
Return myDataTable
End Function
End Class
|