且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

必须声明标量变量“@ customer”。

更新时间:2022-12-25 08:15:26

您创建参数并将它们添加到SQLCommand对象:

 SqlCommand cmd2 =  new  SqlCommand(  update stkdetails set customer = customer + @ customer where empname =' + rows.Cells [ 2 ]。值+  '和date =' + txtdate.Text +  ',con2); 
cmd2.Parameters.AddWithValue( @ customer,rows.Cells [ 7 ]。值);



我也强烈建议您为@设置参数empname和@date同时。

 SqlCommand cmd2 =  new  SqlCommand(  update stkdetails set customer = customer + @ customer where empname = @ empname and date = @ date,con2); 
cmd2.Parameters.AddWithValue( @ customer,rows.Cells [ 7 跨度>]值)。
cmd2.Parameters.AddWithValue( @ empname,rows.Cells [ 2 跨度>]值)。
cmd2.Parameters.AddWithValue( @ date,txtDate.Text);


I am creating windows application using c# 2010, here i am using data grid view for billing purpose, but save the grid view values to data base below error is came 

Must declare the scalar variable "@customer".
 
 SqlCommand cmd2 = new SqlCommand("update stkdetails set customer=customer+@customer" + rows.Cells[7].Value + " where empname='" + rows.Cells[2].Value + "'and date='" + txtdate.Text + "'", con2);


any one give me some ideas how to solve above error



What I have tried:

Must declare the scalar variable "@customer".

You create parameters and add them to the SQLCommand object:
SqlCommand cmd2 = new SqlCommand("update stkdetails set customer=customer+@customer where empname='" + rows.Cells[2].Value + "'and date='" + txtdate.Text + "'", con2);
cmd2.Parameters.AddWithValue("@customer", rows.Cells[7].Value);


I would also strongly suggest you set up parameters for @empname and @date at the same time.

SqlCommand cmd2 = new SqlCommand("update stkdetails set customer=customer+@customer where empname=@empname and date=@date", con2);
cmd2.Parameters.AddWithValue("@customer", rows.Cells[7].Value);
cmd2.Parameters.AddWithValue("@empname", rows.Cells[2].Value);
cmd2.Parameters.AddWithValue("@date", txtDate.Text);