using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace DataAcessLayer
{
internal class DataAccess
{
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}
public static string GetConnection
{
get {
string ConnectionStr = System.Configuration.ConfigurationManager.AppSettings["ConStr"];
return ConnectionStr;
}
}
public static DataTable GetDataFromTable(string SPName, params SqlParameter[] parameters)
{
SqlConnection cn = new SqlConnection(GetConnection);
SqlCommand cmd = new SqlCommand(SPName,cn);
IDataReader dr;
DataTable dt = new DataTable();
cmd.CommandText = SPName;
cmd.CommandType = CommandType.StoredProcedure;
if (parameters != null)
{
foreach (SqlParameter item in parameters)
cmd.Parameters.Add(item);
}
cn.Open();
try {
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr != null)
{
dt.Load(dr);
}
}
catch (SqlException Ex)
{
return null;
}
cn.Close();
cn.Dispose();
cn = null;
cmd.Dispose();
cmd = null;
return dt;
}
public static int Execute(string SPName,params SqlParameter[] parameters)
{
int intERRor = 0;
SqlConnection cn = new SqlConnection(GetConnection);
SqlCommand cmd = new SqlCommand(SPName, cn);
IDataReader dr;
cmd.CommandText = SPName;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter pError = new SqlParameter("@Error",SqlDbType.Int);
pError.Direction = ParameterDirection.Output;
if (parameters != null)
{
cmd.Parameters.Add(pError);
foreach (SqlParameter item in parameters)
{
cmd.Parameters.Add(item);
}
}
cn.Open();
try {
if (parameters != null)
{
cmd.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
intERRor = -1;
}
cn.Dispose();
cn.Close();
cn = null;
cmd.Dispose();
cmd = null;
if (parameters != null)
intERRor = (int)(pError.Value);
return intERRor;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace DataAcessLayer
{
internal class DataAccess
{
public DataAccess()
{
//
// TODO: Add constructor logic here
//
}
public static string GetConnection
{
get {
string ConnectionStr = System.Configuration.ConfigurationManager.AppSettings["ConStr"];
return ConnectionStr;
}
}
public static DataTable GetDataFromTable(string SPName, params SqlParameter[] parameters)
{
SqlConnection cn = new SqlConnection(GetConnection);
SqlCommand cmd = new SqlCommand(SPName,cn);
IDataReader dr;
DataTable dt = new DataTable();
cmd.CommandText = SPName;
cmd.CommandType = CommandType.StoredProcedure;
if (parameters != null)
{
foreach (SqlParameter item in parameters)
cmd.Parameters.Add(item);
}
cn.Open();
try {
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr != null)
{
dt.Load(dr);
}
}
catch (SqlException Ex)
{
return null;
}
cn.Close();
cn.Dispose();
cn = null;
cmd.Dispose();
cmd = null;
return dt;
}
public static int Execute(string SPName,params SqlParameter[] parameters)
{
int intERRor = 0;
SqlConnection cn = new SqlConnection(GetConnection);
SqlCommand cmd = new SqlCommand(SPName, cn);
IDataReader dr;
cmd.CommandText = SPName;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter pError = new SqlParameter("@Error",SqlDbType.Int);
pError.Direction = ParameterDirection.Output;
if (parameters != null)
{
cmd.Parameters.Add(pError);
foreach (SqlParameter item in parameters)
{
cmd.Parameters.Add(item);
}
}
cn.Open();
try {
if (parameters != null)
{
cmd.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
intERRor = -1;
}
cn.Dispose();
cn.Close();
cn = null;
cmd.Dispose();
cmd = null;
if (parameters != null)
intERRor = (int)(pError.Value);
return intERRor;
}
}
}