public void Bills() { try { AllBilling b = new AllBilling(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { b.Name = dataGridView1.Rows[i].Cells[0].Value.ToString(); b.Type = dataGridView1.Rows[i].Cells[3].Value.ToString(); b.Price = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()); b.Quantity = int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()); b.AddedDate = DateTime.Now; b.AddedBy = LoggedInUser.UserName; b.PatientInformationId = billId; db.Bills.Add(b); db.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("error\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }