CODE BEHIND CODE
------------------------- SOME CODE HERE------------
BO
public class DAOAssessmentForm
{
public DAOAssessmentForm()
{
//
// TODO: Add constructor logic here
//
}
private string _id= string.Empty;
public string id
{
get
{ return this._id; }
set
{ this._id= value; }
}
BL
using test.dal;
using test.dao;
public DataTable murali(daoobject objdao)
{
string SpName = "getdataSelectTable";
try
{
return DataAccess.ExecuteReader(SpName, objdao.id );
}
catch (Exception ex)
{
throw ex;
}
}
DAL
using test.dal;
using test.bl
public static DataTable ExecuteReader(string SPName)
{
try
{
DataTable dtResult = new DataTable();
using (SqlConnection connect = new SqlConnection(yes.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
objAdapter.Fill(dtResult);
return dtResult;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
-----------if you have more input parameters then use belowe code------------
public static DataTable ExecuteReader(string SPName, params object[] parameters)
{
try
{
string Param = string.Empty;
if (parameters != null)
{
int Length = parameters.Length;
for (int i = 0; i < Length; i++)
{
Param += parameters[i].ToString();
if (i != (Length - 1))
Param += "','";
}
}
Param = "'" + Param + "'";
SPName = "Exec " + SPName + " " + Param;
DataTable dtResult = new DataTable();
using (SqlConnection connect = new SqlConnection(yes.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
objAdapter.Fill(dtResult);
//con1.Close();
return dtResult;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
----------for the OPERATIONS LIKE INSERT DELETE UPDATE---------
public static int ExecuteNonQuery(string SPName, params object[] parameters)
{
try
{
string Param = string.Empty;
if (parameters != null)
{
int Length = parameters.Length;
for (int i = 0; i < Length; i++)
{
Param += parameters[i].ToString();
if (i != (Length - 1))
Param += "','";
}
}
Param = "'" + Param + "'";
SPName = "Exec " + SPName + " " + Param;
using (SqlConnection connect = new SqlConnection(YES.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
int Result = objCommand.ExecuteNonQuery();
return Result;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
------------------------- SOME CODE HERE------------
BO
public class DAOAssessmentForm
{
public DAOAssessmentForm()
{
//
// TODO: Add constructor logic here
//
}
private string _id= string.Empty;
public string id
{
get
{ return this._id; }
set
{ this._id= value; }
}
}
BL
using test.dal;
using test.dao;
public DataTable murali(daoobject objdao)
{
string SpName = "getdataSelectTable";
try
{
return DataAccess.ExecuteReader(SpName, objdao.id );
}
catch (Exception ex)
{
throw ex;
}
}
DAL
using test.dal;
using test.bl
public static DataTable ExecuteReader(string SPName)
{
try
{
DataTable dtResult = new DataTable();
using (SqlConnection connect = new SqlConnection(yes.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
objAdapter.Fill(dtResult);
return dtResult;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
-----------if you have more input parameters then use belowe code------------
public static DataTable ExecuteReader(string SPName, params object[] parameters)
{
try
{
string Param = string.Empty;
if (parameters != null)
{
int Length = parameters.Length;
for (int i = 0; i < Length; i++)
{
Param += parameters[i].ToString();
if (i != (Length - 1))
Param += "','";
}
}
Param = "'" + Param + "'";
SPName = "Exec " + SPName + " " + Param;
DataTable dtResult = new DataTable();
using (SqlConnection connect = new SqlConnection(yes.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
objAdapter.Fill(dtResult);
//con1.Close();
return dtResult;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
----------for the OPERATIONS LIKE INSERT DELETE UPDATE---------
public static int ExecuteNonQuery(string SPName, params object[] parameters)
{
try
{
string Param = string.Empty;
if (parameters != null)
{
int Length = parameters.Length;
for (int i = 0; i < Length; i++)
{
Param += parameters[i].ToString();
if (i != (Length - 1))
Param += "','";
}
}
Param = "'" + Param + "'";
SPName = "Exec " + SPName + " " + Param;
using (SqlConnection connect = new SqlConnection(YES.ConnectionString))
{
connect.Open();
SqlCommand objCommand = new SqlCommand(SPName.Trim(), connect);
objCommand.CommandTimeout = 0;
int Result = objCommand.ExecuteNonQuery();
return Result;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
Post a Comment (0)