For MVC
Bussiness data layer class in asp.net c#
you can use
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace screentestbrijesh.App_Code
{
public class DataAdoLayer
{
public SqlConnection con;
public SqlCommand cmd;
public SqlDataAdapter da;
public DataAdoLayer()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
}
public bool ExecuteNonQuery(string procedureName)
{
try
{
cmd.CommandText = procedureName;
if (con.State == ConnectionState.Closed)
con.Open();
return cmd.ExecuteNonQuery() > 0 ? true : false;
}
catch (Exception ex)
{
string str = ex.ToString();
return false;
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
public DataTable GetBulkData(string procedureName) {
try
{
DataTable dt = new DataTable();
cmd.CommandText = procedureName;
da.Fill(dt);
return dt;
}
catch (Exception e) {
string str = e.ToString();
return new DataTable();
}
}
}
}
you can use
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace screentestbrijesh.App_Code
{
public class DataAdoLayer
{
public SqlConnection con;
public SqlCommand cmd;
public SqlDataAdapter da;
public DataAdoLayer()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString);
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
}
public bool ExecuteNonQuery(string procedureName)
{
try
{
cmd.CommandText = procedureName;
if (con.State == ConnectionState.Closed)
con.Open();
return cmd.ExecuteNonQuery() > 0 ? true : false;
}
catch (Exception ex)
{
string str = ex.ToString();
return false;
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}
public DataTable GetBulkData(string procedureName) {
try
{
DataTable dt = new DataTable();
cmd.CommandText = procedureName;
da.Fill(dt);
return dt;
}
catch (Exception e) {
string str = e.ToString();
return new DataTable();
}
}
}
}
Comments
Post a Comment