Help! it says The connection was not closed. The connection's current state is ope but i did close it , pls help ? thank you in advance
private void inserttransaction()
{
for (int i = 0; i < dataPOS.Rows.Count; i++)
{
con.Open();
dataPOS.Rows[i].Selected = true;
cmd = new SqlCommand(@"INSERT INTO TRANSACTIONS (TransactionCode,TransactionDate,ItemCode,ItemName,Quantity,Price,Total)
VALUES
('"+ dataPOS.SelectedRows[0].Cells[0].Value.ToString() +"' , '"+ dataPOS.SelectedRows[0].Cells[1].Value.ToString() +"' , '"+ dataPOS.SelectedRows[0].Cells[2].Value.ToString() +"' , '"+ dataPOS.SelectedRows[0].Cells[3].Value.ToString()+"' , '"+ dataPOS.SelectedRows[0].Cells[4].Value.ToString() +"' '"+ dataPOS.SelectedRows[0].Cells[5].Value.ToString() +"' , '"+ dataPOS.SelectedRows[0].Cells[6].Value.ToString() +"')", con);
cmd.ExecuteNonQuery();
dataPOS.Rows[i].Selected = false;
con.Close();
}
}