Create Db Request class
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections;
///
/// Summary description for DBRequest
///
public class DBRequest
{
///
/// Connection String...
///
private string _sConnectionString;
public string ConnectionString
{
get { return _sConnectionString; }
set { _sConnectionString = value; }
}
///
/// SQl Connecion...
///
private SqlConnection _sqlConnection;
public SqlConnection SqlConnection
{
get { return _sqlConnection; }
set { _sqlConnection = value; }
}
private string _sqlCommandText;
public string SqlCommandText
{
get { return _sqlCommandText; }
set { _sqlCommandText = value; }
}
private CommandType _sqlComandType;
public CommandType SqlComandType
{
get { return _sqlComandType; }
set { _sqlComandType = value; }
}
private Hashtable _parameter = new Hashtable();
public Hashtable Parameter
{
get { return _parameter; }
set { _parameter = value; }
}
private Exception _exception;
public Exception Exception
{
get { return _exception; }
set { _exception = value; }
}
public DBRequest()
{
ConnectionString = GetSQLConnectionString();
}
///
/// Get SQL Connection String...
///
///
#region Get SQL Connection String
public string GetSQLConnectionString()
{
return Config.ConnectionString.ToString();
}
#endregion
///
/// Open Sql Connecion....
///
///
/// False = if open not success...
///
public bool OpenSQLConnection()
{
bool isOpenSqlConnecion=false;
try
{
///Get Sql Connecion String....
string _sGetConnectionString = GetSQLConnectionString();
if(!string.IsNullOrEmpty(_sGetConnectionString))
{
///Open Sql Connection.....
SqlConnection = new SqlConnection(_sGetConnectionString);
SqlConnection.Open();
isOpenSqlConnecion=true;
}
}
catch(SqlException sqlEx)
{
isOpenSqlConnecion=false;
throw sqlEx;
}
return isOpenSqlConnecion;
}
///
/// Close Sql Connceion...
///
///
/// False=if close not success
///
public bool CloseSqlConnection()
{
bool isClosedSqlConnecion = false;
try
{
///Check Sql Connection is Exits....
if (SqlConnection != null)
{
if (SqlConnection.State != ConnectionState.Broken || SqlConnection.State != ConnectionState.Closed)
{
///Close Sql Connection....
SqlConnection.Close();
isClosedSqlConnecion = true;
}
}
else
{
isClosedSqlConnecion = false;
}
}
catch (SqlException sqlEx)
{
isClosedSqlConnecion = false;
throw sqlEx;
}
return isClosedSqlConnecion;
}
///
/// Get Sql Connection
///
///
public SqlConnection GetSQLConnection()
{
SqlConnection _sqlConn = SqlConnection;
return _sqlConn;
}
///
/// Add Sql Parameter....
///
/// Parameter Name
/// Parameter Db Type
/// Parameter Value
/// Parameter Direction
public void AddSqlParameter(string parameterName, SqlDbType sqlDbType,object objSqlParameterValue,ParameterDirection parameterDirection)
{
try
{
SqlParameter _sqlParameter = new SqlParameter(parameterName,sqlDbType);
if (_sqlParameter != null)
{
_sqlParameter.Value = objSqlParameterValue;
_sqlParameter.Direction = parameterDirection;
Parameter.Add(parameterName, _sqlParameter);
}
}
catch (SqlException SqlExce)
{
throw SqlExce;
}
}
}



0 comments:
Post a Comment