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 connclass c = new connclass(); 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,quantity=@quantity,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); //Passing 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("@quantity", u.quantity); 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); }
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 connclass c = new connclass(); 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); //Passing 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); }