Weeman Osekre

Weeman Osekre

  • NA
  • 56
  • 3.5k

Data repository

Nov 1 2020 4:15 AM
I am using my repository layer to add items from a datagridview into my database. Some of the data are product ordered, the orders are table number, user, date, total expenditure. But with the code I have, I don’t get all the product that are the datagridview. The data gridview contains 6 of 9 parameters that is to complete the columns in the database table . The 6 are products and its corresponding details. In this case multiple orders are placed into the datagridview but it only saves one items for the table regardless of the number of items in the datagridviewHow do I go about it ?
  1. private void btnsend_Click(object sender, EventArgs e) {  
  2.   var iscorrect = kk.isvaliduser(Int32.Parse(libtabsno.Text));  
  3.   if (!iscorrect) {  
  4.     foreach(DataGridViewRow dr in dataGridView2.Rows) {  
  5.       ck.category = dr.Cells[4].Value.ToString();  
  6.       ck.productname = dr.Cells[2].Value.ToString();  
  7.       string price = (dr.Cells[3].Value.ToString());  
  8.       ck.productprice = double.Parse(price);  
  9.       string ip = (dr.Cells[6].Value.ToString());  
  10.       ck.tprice = double.Parse(ip);  
  11.       ck.productid = Int32.Parse(dr.Cells[1].Value.ToString());  
  12.       ck.quantity = Int32.Parse(dr.Cells[5].Value.ToString());  
  13.     }  
  14.     ck.tabel_sno_ = Int32.Parse(libtabsno.Text);  
  15.     ck.tabel_no_ = Int32.Parse(libtno.Text.ToString());  
  16.     ck.total = Int32.Parse(libt2.Text);  
  17.     ck.date = DateTime.Now;  
  18.     ck.user = libuser.Text;  
  19.     kk.addunpaid(ck);  
  20.   }  
  21. }  
 

Answers (1)