public static bool Insert(Borrower b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert into Borrower(borrowerNumber, name, sex, address, telephone, email)" + "values(@borrowerNumber, @name, @sex, @address, @telephone, @email)", cn); cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber); cmd.Parameters.AddWithValue("@name", b.Name); cmd.Parameters.AddWithValue("@sex", b.Sex); cmd.Parameters.AddWithValue("@address", b.Address); cmd.Parameters.AddWithValue("@telephone", b.Telephone); cmd.Parameters.AddWithValue("@email", b.Email); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (System.Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Delete(Borrower b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Delete Borrower where borrowerNumber = @borrowerNumber", cn); cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Update(Borrower b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Update Borrower set name = @name, " + "sex = @sex, address = @address, telephone=@telephone, email=@email where borrowerNumber = @borrowerNumber", cn); cmd.Parameters.AddWithValue("@borrowerNumber", b.BorrowerNumber); cmd.Parameters.AddWithValue("@name", b.Name); cmd.Parameters.AddWithValue("@sex", b.Sex); cmd.Parameters.AddWithValue("@address", b.Address); cmd.Parameters.AddWithValue("@telephone", b.Telephone); cmd.Parameters.AddWithValue("@email", b.Email); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Update(Borrower b) { return BorrowerDA.Update(b); }
public static bool Insert(Borrower b) { return BorrowerDA.Insert(b); }
public static bool Delete(Borrower b) { return BorrowerDA.Delete(b); }