public void SaveProduct()
{
SqlConnection con = new SqlConnection(sqlcon);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into tbl_Product (BillNo,Prod_Name,Price,Quantity,Sum) values ('" + txtBillNo.Text + "','" + txtprod1.Text + "','" + txtQnt1.Text + "','" + txtPriceUnit1.Text + "','" + txtPrice1.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd2.Text + "','" + txtQnt2.Text + "','" + txtPriceUnit2.Text + "','" + txtPrice2.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd3.Text + "','" + txtQnt3.Text + "','" + txtPriceUnit3.Text + "','" + txtPrice3.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd4.Text + "','" + txtQnt4.Text + "','" + txtPriceUnit4.Text + "','" + txtPrice4.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd5.Text + "','" + txtQnt5.Text + "','" + txtPriceUnit5.Text + "','" + txtPrice5.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd6.Text + "','" + txtQnt6.Text + "','" + txtPriceUnit6.Text + "','" + txtPrice6.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd7.Text + "','" + txtQnt7.Text + "','" + txtPriceUnit7.Text + "','" + txtPrice7.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd8.Text + "','" + txtQnt8.Text + "','" + txtPriceUnit8.Text + "','" + txtPrice8.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd9.Text + "','" + txtQnt9.Text + "','" + txtPriceUnit9.Text + "','" + txtPrice9.Text + "'),"
+ "('" + txtBillNo.Text + "','" + txtProd10.Text + "','" + txtQnt10.Text + "','" + txtPriceUnit10.Text + "','" + txtPrice10.Text + "')", con);
if (cmd.ExecuteNonQuery() > 0)
{
totalCost();
}
}
This is a bill print project. for store maximum 10 record I take these text boxes. But when I want to store less than ten record I get error. So how can I modified this code to store less than 10 or maximum 10 records.