public bool Insert(BLL_DealerCustomer dc) { bool isSuccess = false; //creating db connection SqlConnection conn = new SqlConnection(myconnstrng); DataTable dt = new DataTable(); try { // SQL Query to Get data from db String sql = "INSERT INTO tbl_dea_cust (type, name, email, contact, address, added_date, added_by) VALUES (@type, @name, @email, @contact, @address, @added_date, @added_by)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@type", dc.type); cmd.Parameters.AddWithValue("@name", dc.name); cmd.Parameters.AddWithValue("@email", dc.email); cmd.Parameters.AddWithValue("@contact", dc.contact); cmd.Parameters.AddWithValue("@address", dc.address); cmd.Parameters.AddWithValue("@added_date", dc.added_date); cmd.Parameters.AddWithValue("@added_by", dc.added_by); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is excute successfully then the value to rows will be greater than 0 else it will be less than 0 if (rows > 0) { //Query Successfull isSuccess = true; } else { //query failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool Update(BLL_DealerCustomer dc) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "UPDATE tbl_dea_cust SET type=@type, name=@name, email=@email, contact=@contact, address=@address, added_date=@added_date, added_by=@added_by WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@type", dc.type); cmd.Parameters.AddWithValue("@name", dc.name); cmd.Parameters.AddWithValue("@email", dc.email); cmd.Parameters.AddWithValue("@contact", dc.contact); cmd.Parameters.AddWithValue("@address", dc.address); cmd.Parameters.AddWithValue("@added_date", dc.added_date); cmd.Parameters.AddWithValue("@added_by", dc.added_by); cmd.Parameters.AddWithValue("@id", dc.id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //Query Successfull isSuccess = true; } else { //query failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(BLL_DealerCustomer c) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "DELETE FROM tbl_dea_cust WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", c.id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //Query Successfull isSuccess = true; } else { //query failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }