using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.OleDb;
using 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 static DataTable GetDataTableOleDb(string SQLQuery, string PathToMDB)
    {
        OleDbConnection conn = new OleDbConnection();
        OleDbDataAdapter myAdapter = new OleDbDataAdapter();
        DataTable myDataTable = 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 = null;
        }

        return myDataTable;
    }



    /// <summary>
    /// Returns a DataTable from MS SQL Server.
    /// </summary>
    /// <param name="query">SQL query.</param>
    /// <returns>The DataTable object.</returns>
    public static DataTable GetDataTableSql(string query)
    {
        SqlConnection conn = new SqlConnection();
        SqlDataAdapter myAdapter = new SqlDataAdapter();
        DataTable myDataTable = 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 = null;
        }

        return myDataTable;
    }

}