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.Generic;
public class Connection
{
SqlConnection con = new SqlConnection();
DataTable dataTable;
SqlCommand cmd;
SqlDataAdapter adp;
public Connection()
{
string constring = ConfigurationManager.ConnectionStrings["constrwc"].ToString();
con.ConnectionString = constring;
}
public void sql_insert_data(string procedure_nm, int uid, string fname, string lname, DateTime dob, string gender, string country, string state, string hobby, string photo, string email, string uname, string password)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText =procedure_nm;
SqlParameter userid = new SqlParameter("@uid", SqlDbType.Int);
userid.Value = uid;
SqlParameter first = new SqlParameter("@firstname", SqlDbType.VarChar);
first.Value = fname;
SqlParameter last = new SqlParameter("@lastname", SqlDbType.VarChar);
last.Value = lname;
SqlParameter dob1 = new SqlParameter("@dob", SqlDbType.DateTime);
dob1.Value = dob;
SqlParameter gender1 = new SqlParameter("@gender", SqlDbType.VarChar);
gender1.Value = gender;
SqlParameter country1 = new SqlParameter("@country", SqlDbType.VarChar);
country1.Value = country;
SqlParameter state1 = new SqlParameter("@state", SqlDbType.VarChar);
state1.Value = state;
SqlParameter hob = new SqlParameter("@hobby", SqlDbType.VarChar);
hob.Value = hobby;
SqlParameter image1 = new SqlParameter("@photo", SqlDbType.VarChar);
image1.Value = photo;
SqlParameter email1 = new SqlParameter("@email", SqlDbType.VarChar);
email1.Value = email;
SqlParameter username = new SqlParameter("@username", SqlDbType.VarChar);
username.Value = uname;
SqlParameter pass = new SqlParameter("@password", SqlDbType.VarChar);
pass.Value = password;
cmd.Parameters.Add(userid);
cmd.Parameters.Add(first);
cmd.Parameters.Add(last);
cmd.Parameters.Add(dob1);
cmd.Parameters.Add(gender1);
cmd.Parameters.Add(country1);
cmd.Parameters.Add(state1);
cmd.Parameters.Add(hob);
cmd.Parameters.Add(email1);
cmd.Parameters.Add(image1);
cmd.Parameters.Add(username);
cmd.Parameters.Add(pass);
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
throw(ex);
}
}
public void sql_delete_data(int uid)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "delete_procedure";
SqlParameter userid = new SqlParameter("@uid", SqlDbType.Int);
userid.Value = uid;
cmd.Parameters.Add(userid);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
throw (ex);
}
}
public DataTable sqlSelect(string query)
{
cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.Text;
adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
dataTable = new DataTable();
adp.Fill(dataTable);
return dataTable;
}
public void sqlInsUpdDel(string query)
{
con.Open();
cmd = new SqlCommand(query,con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
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.Generic;
public class Connection
{
SqlConnection con = new SqlConnection();
DataTable dataTable;
SqlCommand cmd;
SqlDataAdapter adp;
public Connection()
{
string constring = ConfigurationManager.ConnectionStrings["constrwc"].ToString();
con.ConnectionString = constring;
}
public void sql_insert_data(string procedure_nm, int uid, string fname, string lname, DateTime dob, string gender, string country, string state, string hobby, string photo, string email, string uname, string password)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText =procedure_nm;
SqlParameter userid = new SqlParameter("@uid", SqlDbType.Int);
userid.Value = uid;
SqlParameter first = new SqlParameter("@firstname", SqlDbType.VarChar);
first.Value = fname;
SqlParameter last = new SqlParameter("@lastname", SqlDbType.VarChar);
last.Value = lname;
SqlParameter dob1 = new SqlParameter("@dob", SqlDbType.DateTime);
dob1.Value = dob;
SqlParameter gender1 = new SqlParameter("@gender", SqlDbType.VarChar);
gender1.Value = gender;
SqlParameter country1 = new SqlParameter("@country", SqlDbType.VarChar);
country1.Value = country;
SqlParameter state1 = new SqlParameter("@state", SqlDbType.VarChar);
state1.Value = state;
SqlParameter hob = new SqlParameter("@hobby", SqlDbType.VarChar);
hob.Value = hobby;
SqlParameter image1 = new SqlParameter("@photo", SqlDbType.VarChar);
image1.Value = photo;
SqlParameter email1 = new SqlParameter("@email", SqlDbType.VarChar);
email1.Value = email;
SqlParameter username = new SqlParameter("@username", SqlDbType.VarChar);
username.Value = uname;
SqlParameter pass = new SqlParameter("@password", SqlDbType.VarChar);
pass.Value = password;
cmd.Parameters.Add(userid);
cmd.Parameters.Add(first);
cmd.Parameters.Add(last);
cmd.Parameters.Add(dob1);
cmd.Parameters.Add(gender1);
cmd.Parameters.Add(country1);
cmd.Parameters.Add(state1);
cmd.Parameters.Add(hob);
cmd.Parameters.Add(email1);
cmd.Parameters.Add(image1);
cmd.Parameters.Add(username);
cmd.Parameters.Add(pass);
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
throw(ex);
}
}
public void sql_delete_data(int uid)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "delete_procedure";
SqlParameter userid = new SqlParameter("@uid", SqlDbType.Int);
userid.Value = uid;
cmd.Parameters.Add(userid);
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
throw (ex);
}
}
public DataTable sqlSelect(string query)
{
cmd = new SqlCommand(query, con);
cmd.CommandType = CommandType.Text;
adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
dataTable = new DataTable();
adp.Fill(dataTable);
return dataTable;
}
public void sqlInsUpdDel(string query)
{
con.Open();
cmd = new SqlCommand(query,con);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
No comments:
Post a Comment