public static bool Delete(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Delete Book where bookNumber = @bookNumber", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Insert(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Insert into Book(bookNumber, title, authors, publisher)"+"values(@bookNumber, @title, @authors, @publisher)", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cmd.Parameters.AddWithValue("@title", b.Title); cmd.Parameters.AddWithValue("@authors", b.Authors); cmd.Parameters.AddWithValue("@publisher", b.Publisher); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (System.Exception ex) { MessageBox.Show(ex.Message); return false; } }
public static bool Update(Book b) { return BookDA.Update(b); }
public static bool Insert(Book b) { return BookDA.Insert(b); }
public static bool Delete(Book b) { return BookDA.Delete(b); }
public static bool Update(Book b) { try { SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Update Book set title = @title, " + "authors = @authors, publisher = @publisher where bookNumber = @bookNumber", cn); cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber); cmd.Parameters.AddWithValue("@title", b.Title); cmd.Parameters.AddWithValue("@authors", b.Authors); cmd.Parameters.AddWithValue("@publisher", b.Publisher); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }