Here are the examples of the csharp api System.Data.SqlClient.SqlConnection.Open() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1316 Examples
19
Source : invoicedal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string id)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_invoice WHERE inv_no = " + id ;
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : invoicedetailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string keyword)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_invoice WHERE customer_name Like '%" + keyword + "%' OR inv_no like '%" + keyword + "%' ";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : logindal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool login(loginbll u)
{
//Create a boolean variable and set its value to false and return it
bool issuccess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to check login
string query = "select * from tbl_users where user_name=@user_name AND preplacedword=@preplacedword AND user_type=@user_type";
//Creating SQL Command to preplaced value
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@preplacedword", u.preplacedword);
cmd.Parameters.AddWithValue("@user_type", u.user_type);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//TO hold the data from database
DataTable dt = new DataTable();
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
//Checking The rows in DataTable
if (dt.Rows.Count > 0)
{
//Login Sucessful
issuccess = true;
}
else
{
//Login Failed
issuccess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issuccess;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_stock";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool exist(Manage_Productsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issuccess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to selecte Data from DAtabase
string query = "select * from tbl_stock where product_name=@product_name AND supplier=@supplier AND catagory=@catagory AND colour_code=@colour_code AND type=@type";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@type", u.type);
cmd.Parameters.AddWithValue("@product_name", u.product_name);
cmd.Parameters.AddWithValue("@supplier", u.supplier);
cmd.Parameters.AddWithValue("@catagory", u.catagory);
cmd.Parameters.AddWithValue("@colour_code", u.colour_code);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//TO hold the data from database
DataTable dt = new DataTable();
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
//Checking The rows in DataTable
if (dt.Rows.Count > 0)
{
//Data Exist
issuccess = true;
}
else
{
//Data not exist
issuccess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issuccess;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable MonthlyAndDailyData(string d1, string d2)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
//string d1 = DateTime.Now.ToString();
try
{
//SQL Query to insert Data in DAtabase
string query = "SELECT* FROM tbl_productdetails WHERE added_date BETWEEN '" + d2 + "' AND '" + d1 + "' ";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return dt;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool delete(product_detailsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to delete Data in DAtabase
string query = "DELETE FROM tbl_productdetails WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : sales_analyticsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string keyword)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_productdetails WHERE product_id Like '%" + keyword + "%' OR product_name like '%" + keyword + "%' OR inv_no like '%" + keyword + "%' OR code like '%" + keyword + "%'";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Catagoriesdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_catagories";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Catagoriesdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool insert(Catagoriesbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Insert into tbl_catagories(catagory,supplier,added_by,added_date)Values(@catagory,@supplier,@added_by,@added_date)";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@catagory", u.catagory);
cmd.Parameters.AddWithValue("@supplier", u.supplier);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : invoicedal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool delete(invoicebll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to delete Data in DAtabase
string query = "DELETE FROM tbl_invoice WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : invoicedal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool update(invoicebll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "UPDATE tbl_invoice set inv_no=@inv_no, customer_name=@customer_name,total_payable=@total_payable,paid_amount=@paid_amount,discount=@discount,due_amount=@due_amount,change_amount=@change_amount,added_by=@added_by,sales_date=@sales_date WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
cmd.Parameters.AddWithValue("@inv_no", u.inv_no);
cmd.Parameters.AddWithValue("@customer_name", u.customer_name);
cmd.Parameters.AddWithValue("@total_payable", u.total_payable);
cmd.Parameters.AddWithValue("@paid_amount", u.paid_amount);
cmd.Parameters.AddWithValue("@discount", u.discount);
cmd.Parameters.AddWithValue("@due_amount", u.due_amount);
cmd.Parameters.AddWithValue("@change_amount", u.change_amount);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@sales_date", u.sales_date);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : invoicedal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable BetweenTwoDates(string d1, string d2)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to insert Data in DAtabase
string query = "SELECT* FROM tbl_invoice WHERE sales_date BETWEEN '" + d1 + "' AND '" + d2 + "'";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return dt;
}
19
Source : invoicedetailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_invoice";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool insert(Manage_Productsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Insert into tbl_stock(product_name,colour_code,supplier,catagory,purchase_price,retail_price,type,quanreplacedy,added_by,added_date)Values(@product_name,@colour_code,@supplier,@catagory,@purchase_price,@retail_price,@type,@quanreplacedy,@added_by,@added_date)";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@product_name", u.product_name);
cmd.Parameters.AddWithValue("@colour_code", u.colour_code);
cmd.Parameters.AddWithValue("@supplier" , u.supplier);
cmd.Parameters.AddWithValue("@catagory", u.catagory);
cmd.Parameters.AddWithValue("@purchase_price", u.purchase_price);
cmd.Parameters.AddWithValue("@retail_price", u.retail_price);
cmd.Parameters.AddWithValue("@type", u.type);
cmd.Parameters.AddWithValue("@quanreplacedy", u.quanreplacedy);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string keyword)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_stock WHERE colour_code Like '%" + keyword + "%' OR product_name like '%" + keyword + "%' OR supplier like '%" + keyword + "%' OR catagory like '%" + keyword + "%' OR id like '%" + keyword + "%'";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public Manage_Productsbll GetProductpriceFromId(string id)
{
//First Create an Object of BLL and REturn it
Manage_Productsbll p = new Manage_Productsbll();
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//Data TAble to Holdthe data temporarily
DataTable dt = new DataTable();
try
{
//SQL Query to Get id based on Name
string sql = "SELECT purchase_price FROM tbl_stock WHERE id='" + id + "'";
//Create the SQL Data Adapter to Execute the Query
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
conn.Open();
//Preplaceding the VAlue from Adapter to DAtatable
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
//Preplaced the value from dt to variable
p.purchase_price = dt.Rows[0]["purchase_price"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return p;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool insert(usersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Insert into tbl_users(user_name,user_type,preplacedword,email,cnic,adress,phone_no,added_by,added_date)Values(@user_name,@user_type,@preplacedword,@email,@cnic,@adress,@phone_no,@added_by,@added_date)";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@user_type", u.user_type);
cmd.Parameters.AddWithValue("@preplacedword", u.preplacedword);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@cnic", u.cnic);
cmd.Parameters.AddWithValue("@adress", u.adress);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string keyword)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_users WHERE id Like '%" + keyword + "%' OR user_name like '%" + keyword + "%' OR user_type like '%" + keyword + "%' OR adress like '%" + keyword + "%' ";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool exist(usersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issuccess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to selecte Data from DAtabase
string query = "select * from tbl_users where user_name=@user_name AND cnic=@cnic AND email=@email AND phone_no=@phone_no ";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@cnic", u.cnic);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//TO hold the data from database
DataTable dt = new DataTable();
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
//Checking The rows in DataTable
if (dt.Rows.Count > 0)
{
//Data Exist
issuccess = true;
}
else
{
//Data not exist
issuccess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issuccess;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public usersbll GetIDFromUsername(string username)
{
//Connecting user BLL for getting id
usersbll u = new usersbll();
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to get Data from DAtabase
string sql = "SELECT id FROM tbl_users WHERE user_name='" + username + "'";
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
//Checking The rows in DataTable
if (dt.Rows.Count > 0)
{
//Getting id from DataTable
u.id = int.Parse(dt.Rows[0]["id"].ToString());
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return u;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool insert(product_detailsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Insert into tbl_productdetails(product_id,product_name,price,quanreplacedy,discount,total,purchase_price,inv_no,type,added_by,added_date,code)Values(@product_id,@product_name,@price,@quanreplacedy,@discount,@total,@purchase_price,@inv_no,@type,@added_by,@added_date,@code)";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@product_id", u.product_id);
cmd.Parameters.AddWithValue("@product_name", u.product_name);
cmd.Parameters.AddWithValue("@price", u.price);
cmd.Parameters.AddWithValue("@quanreplacedy", u.quanreplacedy);
cmd.Parameters.AddWithValue("@discount", u.discount);
cmd.Parameters.AddWithValue("@total", u.total);
cmd.Parameters.AddWithValue("@purchase_price", u.purchase_price);
cmd.Parameters.AddWithValue("@inv_no", u.inv_no);
cmd.Parameters.AddWithValue("@type", u.type);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
cmd.Parameters.AddWithValue("@code", u.code);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public decimal GetProductQty(int id)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//Create a Decimal Variable and set its default value to 0
decimal quanreplacedy = 0;
//Create Data Table to save the data from database temporarily
DataTable dt = new DataTable();
try
{
//Write WQL Query to Get Quanreplacedy from Database
string sql = "SELECT quanreplacedy FROM tbl_productdetails WHERE id = " + id;
//Cerate A SqlCommand
SqlCommand cmd = new SqlCommand(sql, conn);
//Create a SQL Data Adapter to Execute the query
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//open DAtabase Connection
conn.Open();
//Preplaced the calue from Data Adapter to DataTable
adapter.Fill(dt);
//Lets check if the datatable has value or not
if (dt.Rows.Count > 0)
{
quanreplacedy = decimal.Parse(dt.Rows[0]["quanreplacedy"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//Close Database Connection
conn.Close();
}
return quanreplacedy;
}
19
Source : sales_analyticsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_productdetails";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_suppliers";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : Manage Products.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool fillcombo()
{
bool issucess = false;
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
string query = "select* from tbl_suppliers";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader myreader;
conn.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string sname = myreader.GetString(1);
txtsupplier.Items.Add(sname);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return issucess;
}
19
Source : Manage Products.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool fillcombo1()
{
bool issucess = false;
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
string query = "select* from tbl_catagories";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataReader myreader;
conn.Open();
myreader = cmd.ExecuteReader();
while (myreader.Read())
{
string sname = myreader.GetString(1);
txtcatagory.Items.Add(sname);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return issucess;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool delete(usersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to delete Data in DAtabase
string query = "DELETE FROM tbl_users WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : invoicedal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable MonthlyAndDailyData(string d1, string d2)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
//string d1 = DateTime.Now.ToString();
try
{
//SQL Query to insert Data in DAtabase
string query = "SELECT* FROM tbl_invoice WHERE sales_date BETWEEN '" + d2 + "' AND '" + d1 + "' ";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return dt;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool update_(Manage_Productsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to update Data in DAtabase
string query = "UPDATE tbl_stock set product_name=@product_name,colour_code=@colour_code,supplier=@supplier,catagory=@catagory,purchase_price=@purchase_price,retail_price=@retail_price,type=@type,quanreplacedy=@quanreplacedy WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
cmd.Parameters.AddWithValue("@product_name", u.product_name);
cmd.Parameters.AddWithValue("@colour_code", u.colour_code);
cmd.Parameters.AddWithValue("@supplier", u.supplier);
cmd.Parameters.AddWithValue("@catagory", u.catagory);
cmd.Parameters.AddWithValue("@purchase_price", u.purchase_price);
cmd.Parameters.AddWithValue("@retail_price", u.retail_price);
cmd.Parameters.AddWithValue("@type", u.type);
cmd.Parameters.AddWithValue("@quanreplacedy", u.quanreplacedy);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool delete(Manage_Productsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to delete Data in DAtabase
string query = "DELETE FROM tbl_stock WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public Manage_Productsbll GetProductIDFromName(string ProductName, string type, string code)
{
//First Create an Object of BLL and REturn it
Manage_Productsbll p = new Manage_Productsbll();
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//Data TAble to Holdthe data temporarily
DataTable dt = new DataTable();
try
{
//SQL Query to Get id based on Name
string sql = "SELECT id FROM tbl_stock WHERE product_name='" + ProductName + "' AND type = '"+ type + "' AND colour_code = '" + code + "'";
//Create the SQL Data Adapter to Execute the Query
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
conn.Open();
//Preplaceding the CAlue from Adapter to DAtatable
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
//Preplaced the value from dt to DeaCustBLL dc
p.id = int.Parse(dt.Rows[0]["id"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return p;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public decimal GetProductQty(int id)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//Create a Decimal Variable and set its default value to 0
decimal quanreplacedy = 0;
//Create Data Table to save the data from database temporarily
DataTable dt = new DataTable();
try
{
//Write WQL Query to Get Quanreplacedy from Database
string sql = "SELECT quanreplacedy FROM tbl_stock WHERE id = " + id;
//Cerate A SqlCommand
SqlCommand cmd = new SqlCommand(sql, conn);
//Create a SQL Data Adapter to Execute the query
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//open DAtabase Connection
conn.Open();
//Preplaced the calue from Data Adapter to DataTable
adapter.Fill(dt);
//Lets check if the datatable has value or not
if (dt.Rows.Count > 0)
{
quanreplacedy = decimal.Parse(dt.Rows[0]["quanreplacedy"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//Close Database Connection
conn.Close();
}
return quanreplacedy;
}
19
Source : Manage_Productsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool UpdateQuanreplacedy(int id, decimal quanreplacedy)
{
//Create a Boolean Variable and Set its value to false
bool success = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//Write the SQL Query to Update Qty
string sql = "UPDATE tbl_stock SET quanreplacedy=@quanreplacedy WHERE id=@id";
//Create SQL Command to Preplaced the calue into Queyr
SqlCommand cmd = new SqlCommand(sql, conn);
//Preplaceding the VAlue trhough parameters
cmd.Parameters.AddWithValue("@quanreplacedy", quanreplacedy);
cmd.Parameters.AddWithValue("@id", id);
//Open Database Connection
conn.Open();
//Create Int Variable and Check whether the query is executed Successfully or not
int rows = cmd.ExecuteNonQuery();
//Lets check if the query is executed Successfully or not
if (rows > 0)
{
//Query Executed Successfully
success = true;
}
else
{
//Failed to Execute Query
success = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return success;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool update(product_detailsbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "UPDATE tbl_productdetails set product_id=@product_id,product_name=@product_name,price=@price,quanreplacedy=@quanreplacedy,discount=@discount,total=@total,purchase_price=@purchase_price,inv_no=@inv_no,type=@type,added_by=@added_by,added_date=@added_date,code=@code WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
cmd.Parameters.AddWithValue("@product_id", u.product_id);
cmd.Parameters.AddWithValue("@product_name", u.product_name);
cmd.Parameters.AddWithValue("@price", u.price);
cmd.Parameters.AddWithValue("@quanreplacedy", u.quanreplacedy);
cmd.Parameters.AddWithValue("@discount", u.discount);
cmd.Parameters.AddWithValue("@total", u.total);
cmd.Parameters.AddWithValue("@purchase_price", u.purchase_price);
cmd.Parameters.AddWithValue("@inv_no", u.inv_no);
cmd.Parameters.AddWithValue("@type", u.type);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
cmd.Parameters.AddWithValue("@code", u.code);
//Database Connection Open
conn.Open();
//To execute non query
int rows = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (rows > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable BetweenTwoDates(string d1, string d2)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to insert Data in DAtabase
string query = "SELECT* FROM tbl_productdetails WHERE added_date BETWEEN '"+d1+"' AND '"+d2+"'";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return dt;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string inv_no)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_productdetails WHERE inv_no = " + inv_no ;
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : product_detailsdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool UpdateQuanreplacedy(int id, decimal quanreplacedy)
{
//Create a Boolean Variable and Set its value to false
bool success = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//Write the SQL Query to Update Qty
string sql = "UPDATE tbl_productdetails SET quanreplacedy=@quanreplacedy WHERE id=@id";
//Create SQL Command to Preplaced the calue into Queyr
SqlCommand cmd = new SqlCommand(sql, conn);
//Preplaceding the VAlue trhough parameters
cmd.Parameters.AddWithValue("@quanreplacedy", quanreplacedy);
cmd.Parameters.AddWithValue("@id", id);
//Open Database Connection
conn.Open();
//Create Int Variable and Check whether the query is executed Successfully or not
int rows = cmd.ExecuteNonQuery();
//Lets check if the query is executed Successfully or not
if (rows > 0)
{
//Query Executed Successfully
success = true;
}
else
{
//Failed to Execute Query
success = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return success;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool insert(suppliersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Insert into tbl_suppliers(user_name,email,company,adress,phone_no,added_by,added_date)Values(@user_name,@email,@company,@adress,@phone_no,@added_by,@added_date)";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@company", u.company);
cmd.Parameters.AddWithValue("@adress", u.adress);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool update(suppliersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to update Data in DAtabase
string query = "UPDATE tbl_suppliers set user_name=@user_name,email=@email,company=@company,adress=@adress,phone_no=@phone_no WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@company", u.company);
cmd.Parameters.AddWithValue("@adress", u.adress);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool delete(suppliersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to delete Data in DAtabase
string query = "DELETE FROM tbl_suppliers WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable Search(string keyword)
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to search Data from DAtabase
string query = "SELECT* FROM tbl_suppliers WHERE id Like '%" + keyword + "%' OR user_name like '%" + keyword + "%' OR company like '%" + keyword + "%'";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : suppliersdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool exist(suppliersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issuccess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to selecte Data from DAtabase
string query = "select * from tbl_suppliers where email=@email AND phone_no=@phone_no";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//TO hold the data from database
DataTable dt = new DataTable();
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
//Checking The rows in DataTable
if (dt.Rows.Count > 0)
{
//Data Exist
issuccess = true;
}
else
{
//Data not exist
issuccess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issuccess;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public DataTable select()
{
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
//TO hold the data from database
DataTable dt = new DataTable();
try
{
//SQL Query to Get Data From DAtabase
string query = "select* from tbl_users";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Getting DAta from dAtabase
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
//Database Connection Open
conn.Open();
//Fill Data in our DataTable
adapter.Fill(dt);
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
//Return the value in DataTable
return dt;
}
19
Source : userdal.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool update(usersbll u)
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to update Data in DAtabase
string query = "UPDATE tbl_users set user_name=@user_name,user_type=@user_type,preplacedword=@preplacedword,email=@email,cnic=@cnic,adress=@adress,phone_no=@phone_no WHERE id=@id";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Preplaceding Values to the Variables
cmd.Parameters.AddWithValue("@id", u.id);
cmd.Parameters.AddWithValue("@user_name", u.user_name);
cmd.Parameters.AddWithValue("@user_type", u.user_type);
cmd.Parameters.AddWithValue("@preplacedword", u.preplacedword);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@cnic", u.cnic);
cmd.Parameters.AddWithValue("@adress", u.adress);
cmd.Parameters.AddWithValue("@phone_no", u.phone_no);
//Database Connection Open
conn.Open();
//To execute non query
int row = cmd.ExecuteNonQuery();
//If the query is executed Successfully then the value to rows will be greater than 0 else it will be less than 0
if (row > 0)
{
//Query Sucessfull
issucess = true;
}
else
{
//Query Failed
issucess = false;
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : Sale Register.cs
with MIT License
from bilalmehrban
with MIT License
from bilalmehrban
public bool ToGetInvoiceID()
{
//Create a boolean variable and set its value to false and return it
bool issucess = false;
int a;
//MEthod to connect Database
connclreplaced c = new connclreplaced();
SqlConnection conn = new SqlConnection(c.connection);
try
{
//SQL Query to insert Data in DAtabase
string query = "Select Max (inv_no) From tbl_invoice";
//For Executing Command
SqlCommand cmd = new SqlCommand(query, conn);
//Database Connection Open
conn.Open();
//To execute reader
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string val = dr[0].ToString();
if (val == "")
{
lblinvoiceno.Text = "1";
}
else
{
a = Convert.ToInt32(dr[0].ToString());
a = a + 1;
lblinvoiceno.Text = a.ToString();
}
}
}
catch (Exception ex)
{
//Throw Message if any error occurs
MessageBox.Show(ex.Message);
}
finally
{
//Closing Connection
conn.Close();
}
return issucess;
}
19
Source : VaultMsSqlBackup.cs
with MIT License
from burki169
with MIT License
from burki169
public bool Restore(string databaseName, string physicalPath)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
var sb = new StringBuilder();
sb.AppendLine("USE [master]");
sb.AppendLine("ALTER DATABASE " + databaseName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
sb.AppendLine("RESTORE DATABASE " + databaseName + " FROM DISK='" + physicalPath + "'");
sb.AppendLine("WAITFOR DELAY '00:00:02'");
sb.AppendLine("ALTER DATABASE " + databaseName + " SET MULTI_USER");
cmd.CommandText = sb.ToString();
cmd.ExecuteNonQuery();
}
return true;
}
19
Source : VaultMsSqlBackup.cs
with MIT License
from burki169
with MIT License
from burki169
public bool Backup(string databaseName, string physicalPath)
{
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
StringBuilder sb = new StringBuilder();
sb.AppendLine("BACKUP DATABASE " + databaseName + " ");
sb.AppendLine("TO DISK='" + physicalPath + "'");
cmd.CommandText = sb.ToString();
cmd.ExecuteNonQuery();
}
return true;
}
19
Source : DbLoggingTest.cs
with MIT License
from capslocky
with MIT License
from capslocky
private static int LogRequest(string origin, string operation, string request, string location)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "insert into [Requests] (Origin, Operation, Location, Request) values (@origin, @operation, @location, @request); select @@IDENreplacedY;";
command.Parameters.AddWithValue("origin", origin);
command.Parameters.AddWithValue("operation", operation);
command.Parameters.AddWithValue("location", location);
command.Parameters.AddWithValue("request", request);
var result = command.ExecuteScalar();
return Convert.ToInt32(result);
}
}
}
19
Source : DbLoggingTest.cs
with MIT License
from capslocky
with MIT License
from capslocky
private static void LogResponse(string response, int id)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "update [Requests] set Response = @response where ID = @id";
command.Parameters.AddWithValue("response", response);
command.Parameters.AddWithValue("id", id);
command.ExecuteNonQuery();
}
}
}
See More Examples