我有一个 Windows 应用程序,我想在其中填写采购订单。它有一个名为 uom 的字段。现在我正在使用参数化查询插入。但我收到了这个错误
必须声明标量变量@uom。
请帮忙。
private void btnsave_Click(object sender, EventArgs e)
{
con.Open();
if (IsAllValid())
{
cmd.CommandText = "insert into purchaseorder(req_no,purchaseorder_no,purchaseorder_date,costcenter_id,vendor_id,payment_terms,delivery_schedule,emp_id,commercial_name) values(@req_no,@purchaseorder_no,@purchaseorder_date,@costcenter_id,@vendor_id,@payment_terms,@delivery_schedule,@emp_id,@commercial_name)";
cmd.Parameters.AddWithValue("@req_no", cmbreqno.SelectedValue);
cmd.Parameters.AddWithValue("@purchaseorder_no", txtpno.Text);
cmd.Parameters.AddWithValue("@purchaseorder_date", dtpo.Value);
cmd.Parameters.AddWithValue("@costcenter_id", Convert.ToString(txtcc.Tag));
cmd.Parameters.AddWithValue("@vendor_id", cmbvendorname.SelectedValue);
cmd.Parameters.AddWithValue("@payment_terms", txtpaymentterms.Text);
cmd.Parameters.AddWithValue("@delivery_schedule", txtdeliveryschedule.Text);
cmd.Parameters.AddWithValue("@emp_id", cmbcontactperson.SelectedValue);
cmd.Parameters.AddWithValue("@commercial_name", txtcommercial.Text);
cmd.ExecuteScalar();
foreach (var item in poitemlist)
{
cmd.CommandText = "insert into purchaseorderitem(uom,item_id,quantity,item_cost,total_cost)values(@uom,@item_id,@quantity,@item_cost,@total_cost)";
cmd.Parameters.AddWithValue("@item_id", item.Item_ID.ToString());
cmd.Parameters.AddWithValue("@uom", item.uom.ToString());
cmd.Parameters.AddWithValue("@quantity", item.Quantity.ToString());
cmd.Parameters.AddWithValue("@item_cost", item.price.ToString());
cmd.Parameters.AddWithValue("@total_cost", item.TotalCost.ToString());
cmd.Parameters.Clear();
cmd.ExecuteScalar();
}
MessageBox.Show("Purchase Order saved", "Purchase Order", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("error", "Purchase Order", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
con.Close();
}