private void SaveBook_Click(object sender, EventArgs e) { Modelss.Book bok = new Modelss.Book(); using (Modelss.KITABXANADB db = new Modelss.KITABXANADB()) { } Modelss.Category ct = new Modelss.Category(); string bookN = bookname.Text.ToString(); string autor = cbAuthor.SelectedItem.ToString(); string pricee = bookprice.Text.ToString(); string ctg = categoryCB.SelectedItem.ToString(); string countt = bookcount.Text.ToString(); decimal dbprice = Convert.ToDecimal(bookprice.Text); dgvBooks.Rows.Add(bookN, autor, pricee, ctg, countt); bok.CategoryID = 2; bok.Name = bookN; bok.Price = dbprice; bok.Count = Convert.ToInt32(countt); using (Modelss.KITABXANADB db = new Modelss.KITABXANADB()) { db.Books.Add(bok); db.SaveChanges(); } }
private void Button1_Click(object sender, EventArgs e) { using (Modelss.KITABXANADB db = new Modelss.KITABXANADB()) { Modelss.Category ctgr = new Modelss.Category(); ctgr.Name = ctgrtxt.Text; db.Categories.Add(ctgr); db.SaveChanges(); } ctgDVG.Rows.Add(ctgrtxt.Text); }