public bool Insert(RespondersBLL resp) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "INSERT INTO tbl_Responders (IDNumber, Name, Address, Contact, Email, Age, Gender, Position, Qualifications, Birthdate, Remarks, PathImage) VALUES (@IDNumber, @Name, @Address, @Contact, @Email, @Age, @Gender, @Position, @Qualifications, @Birthdate, @Remarks, @PathImage)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@IDNumber", resp.IDNumber); cmd.Parameters.AddWithValue("@Name", resp.Name); cmd.Parameters.AddWithValue("@Address", resp.Address); cmd.Parameters.AddWithValue("@Contact", resp.Contact); cmd.Parameters.AddWithValue("@Email", resp.Email); cmd.Parameters.AddWithValue("@Age", resp.Age); cmd.Parameters.AddWithValue("@Gender", resp.Gender); cmd.Parameters.AddWithValue("@Position", resp.Position); cmd.Parameters.AddWithValue("@Qualifications", resp.Qualifications); cmd.Parameters.AddWithValue("@Birthdate", resp.Birthdate); cmd.Parameters.AddWithValue("@Remarks", resp.Remarks); cmd.Parameters.AddWithValue("@PathImage", @"\Images\Responders\" + resp.PathImage); conn.Open(); int rows = cmd.ExecuteNonQuery(); // If the query is executed successfully then the value to rows will be greaten than 0 else it will be less than 0 if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Insert data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }
public bool Update(RespondersBLL resp) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "UPDATE tbl_Responders SET IDNumber=@IDNumber, Name=@Name, Address=@Address, Contact=@Contact, Email=@Email, Age=@Age, Gender=@Gender, Position=@Position, Qualifications=@Qualifications, Birthdate=@Birthdate, Remarks=@Remarks, PathImage=@PathImage WHERE ID=@ID"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@ID", resp.ID); cmd.Parameters.AddWithValue("@IDNumber", resp.IDNumber); cmd.Parameters.AddWithValue("@Name", resp.Name); cmd.Parameters.AddWithValue("@Address", resp.Address); cmd.Parameters.AddWithValue("@Contact", resp.Contact); cmd.Parameters.AddWithValue("@Email", resp.Email); cmd.Parameters.AddWithValue("@Age", resp.Age); cmd.Parameters.AddWithValue("@Gender", resp.Gender); cmd.Parameters.AddWithValue("@Position", resp.Position); cmd.Parameters.AddWithValue("@Qualifications", resp.Qualifications); cmd.Parameters.AddWithValue("@Birthdate", resp.Birthdate); cmd.Parameters.AddWithValue("@Remarks", resp.Remarks); cmd.Parameters.AddWithValue("@PathImage", @"\Images\Responders\" + resp.PathImage); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Update data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(RespondersBLL resp) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "DELETE FROM tbl_Responders WHERE ID=@ID"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@ID", resp.ID); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Delete data from Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }