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;
///
/// Summary description for DAL
///
public class DAL
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter sda;
String ConString;
public DAL()
{
ConString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
con = new SqlConnection(ConString);
}
public void ConnectionOpen()
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
}
public void ConnectionClose()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
public DataTable GetDataTable(String query)
{
sda = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
public int PutData(String query)
{
cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
int a = cmd.ExecuteNonQuery();
con.Close();
return a;
}
public string ExecuteScaler(String query)
{
cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
string s = Convert.ToString(cmd.ExecuteScalar());
con.Close();
return s;
}
public void FillCombo(DropDownList ddl, String query, String item, String Value, String ZerothElemnt, int SelectedIndex)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
ddl.DataSource = dt;
ddl.DataTextField = item;
ddl.DataValueField = Value;
ddl.DataBind();
ddl.Items.Insert(0, ZerothElemnt);
ddl.SelectedIndex = SelectedIndex;
}
public void FillCombo(DropDownList ddl, String query, String item, String Value, int SelectedIndex)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
ddl.DataSource = dt;
ddl.DataBind();
ddl.SelectedIndex = SelectedIndex;
}
public void FillGrid(GridView grd, String query)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
grd.DataSource = dt;
grd.DataBind();
}
public void FillDetailView(DetailsView dv, String query)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
dv.DataSource = dt;
dv.DataBind();
}
-----------------------------------------------
public void Fillcombo(System.Windows.Forms.ComboBox cmbo, string display, string value, string sqlstr)
{
DataTable dtcombo = new DataTable();
myconnection();
cmd.CommandText = sqlstr;
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
adp.SelectCommand = cmd;
adp.Fill(dtcombo);
cmbo.DataSource = dtcombo;
cmbo.ValueMember = dtcombo.Columns[value].ToString();
cmbo.DisplayMember = dtcombo.Columns[display].ToString();
}
public void Deletefun(string qry)
{
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.DeleteCommand = cmd;
cmd.ExecuteNonQuery();
//adp.InsertCommand.ExecuteNonQuery();
}
public void Updatefun(string qry)
{
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.UpdateCommand = cmd;
cmd.ExecuteNonQuery();
//adp.InsertCommand.ExecuteNonQuery();
}
public DataTable FindFun(string qry)
{
dt.Clear();
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
return dt;
}
}
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;
///
/// Summary description for DAL
///
public class DAL
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter sda;
String ConString;
public DAL()
{
ConString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
con = new SqlConnection(ConString);
}
public void ConnectionOpen()
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
}
public void ConnectionClose()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
public DataTable GetDataTable(String query)
{
sda = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
public int PutData(String query)
{
cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
int a = cmd.ExecuteNonQuery();
con.Close();
return a;
}
public string ExecuteScaler(String query)
{
cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
con.Open();
string s = Convert.ToString(cmd.ExecuteScalar());
con.Close();
return s;
}
public void FillCombo(DropDownList ddl, String query, String item, String Value, String ZerothElemnt, int SelectedIndex)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
ddl.DataSource = dt;
ddl.DataTextField = item;
ddl.DataValueField = Value;
ddl.DataBind();
ddl.Items.Insert(0, ZerothElemnt);
ddl.SelectedIndex = SelectedIndex;
}
public void FillCombo(DropDownList ddl, String query, String item, String Value, int SelectedIndex)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
ddl.DataSource = dt;
ddl.DataBind();
ddl.SelectedIndex = SelectedIndex;
}
public void FillGrid(GridView grd, String query)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
grd.DataSource = dt;
grd.DataBind();
}
public void FillDetailView(DetailsView dv, String query)
{
DataTable dt = new DataTable();
dt = GetDataTable(query);
dv.DataSource = dt;
dv.DataBind();
}
-----------------------------------------------
public void Fillcombo(System.Windows.Forms.ComboBox cmbo, string display, string value, string sqlstr)
{
DataTable dtcombo = new DataTable();
myconnection();
cmd.CommandText = sqlstr;
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
adp.SelectCommand = cmd;
adp.Fill(dtcombo);
cmbo.DataSource = dtcombo;
cmbo.ValueMember = dtcombo.Columns[value].ToString();
cmbo.DisplayMember = dtcombo.Columns[display].ToString();
}
public void Deletefun(string qry)
{
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.DeleteCommand = cmd;
cmd.ExecuteNonQuery();
//adp.InsertCommand.ExecuteNonQuery();
}
public void Updatefun(string qry)
{
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.UpdateCommand = cmd;
cmd.ExecuteNonQuery();
//adp.InsertCommand.ExecuteNonQuery();
}
public DataTable FindFun(string qry)
{
dt.Clear();
myconnection();
cmd.Connection = con;
cmd.CommandText = qry;
cmd.CommandType = CommandType.Text;
adp.SelectCommand = cmd;
adp.Fill(dt);
return dt;
}
}
No comments:
Post a Comment