I've designed two tables (Sale and SaleList),here is a relationship between them (one to many) the sale table is the master and the second is the child, Sale Fields are (Id - SaleNum - CustomerName - Description),SaleList Fields are (Id - SaleId - Num - ItemName - Qut - Unit - SalePrice - Total),Iam adding the rows manually to gridview and passing the item data to it from itemcard table, I want to enter the data in the rows to the database, and you create a button to perform this operation, suppose you add two rows when you press the button to save the data in the database, it transfer only one row out of two rows This is my problem
private void simpleButton1_Click(object sender, EventArgs e)
{
Sale sale = new Sale()
{
SaleNum = int.Parse(txtSaleId.Text),
CustomerName = txtCustomer.Text,
Description = txtDescription.Text
};
db.Sales.InsertOnSubmit(sale);
db.SubmitChanges();
for (int i = 0; i < gvSale.DataRowCount; i++)
{
SaleList sList = new SaleList()
{
SaleId = int.Parse(gvSale.GetRowCellValue(i,"SaleId").ToString()),
//ItemId = int.Parse(row.Cells[3].Value.ToString()),
Num = gvSale.GetRowCellValue(i, "Num").ToString(),
ItemName = gvSale.GetRowCellValue(i, "ItemName").ToString(),
Qut = double.Parse(gvSale.GetRowCellValue(i, "Qut").ToString()),
Unit = gvSale.GetRowCellValue(i, "Unit").ToString(),
SalePrice = double.Parse(gvSale.GetRowCellValue(i, "SalePrice").ToString()),
Total = 0,
};
db.SaleLists.InsertOnSubmit(sList);
db.SubmitChanges();
}
}
The problem is inserting only the data in the first row to database.