|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /home/queenjbs/www/FusionChart/Code/CS/App_Code/ |
Upload File : |
using System;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Configuration;
namespace DataConnection
{
/// <summary>
/// DataBase Connection Class.
/// </summary>
public class DbConn
{
// Create a database Connection. using here Access Database
// Return type object of OdbcConnection
public OdbcConnection connection;
public OdbcDataReader ReadData;
public OdbcCommand aCommand;
/// <summary>
/// Data Connection and get Data Reader
/// </summary>
/// <param name="strQuery">SQL Query</param>
public DbConn(string strQuery)
{
// MS Access DataBase Connection - Defined in Web.Config
string connectionName = "MSAccessConnection";
// SQL Server DataBase Connection - Defined in Web.Config
//string connectionName = "SQLServerConnection";
// Creating Connection string using web.config connection string
string ConnectionString = ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;
try
{
// create connection object
connection = new OdbcConnection();
// set connection string
connection.ConnectionString = ConnectionString;
// open connection
connection.Open();
// get reader
GetReader(strQuery);
}
catch (Exception e)
{
HttpContext.Current.Response.Write(e.Message.ToString());
}
}
// Create an instance dataReader
// Return type object of OdbcDataReader
/// <summary>
/// Get Data Reader
/// </summary>
/// <param name="strQuery">SQL Query</param>
public void GetReader(string strQuery)
{
// Create a Command object
aCommand = new OdbcCommand(strQuery, connection);
// Create data reader object using strQuery string
// Auto close connection
ReadData = aCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
}
}