private void btnPostSale_Click(object sender, EventArgs e)
{
string insert;
insert = "INSERT INTO tblInvoiceLines(stockItems) VALUES (@stockItems)";//, itemDescription, quantity, sellingPrice, totalAmountInvoiceLines) VALUES (@stockItems, @itemDescription, @quantity, @sellingPrice, @totalAmountInvoiceLines)";
con.Open();
cmd = new SqlCommand(insert, con);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
//all the lines entered in datagrid view should be store in sql sever databse
cmd.Parameters.Add("@stockItems", dataGridView1.CurrentRow.Cells[i].Value);
}
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("New data has being entered");
}
我在使用循环语句尝试将数据插入sql server时遇到了麻烦,因为我总是得到一个expccetion错误。请帮忙。enter image description here