将数据网格视图中输入的数据插入数据库系统时出现问题

时间:2017-10-04 11:25:50

标签: c# sql-server

        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

0 个答案:

没有答案