声明标量变量错误 [英] Declare the scalar variable error

查看:76
本文介绍了声明标量变量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:



Here is my code:

if (chkUpdate.Checked)
               {
                   string strID = GridView1.Rows[i].Cells[1].Text;
                 string v_item_no = GridView1.Rows[i].Cells[4].Text;
                   string strName = ((TextBox)GridView1.Rows[i].FindControl("txtName")).Text;
                   string strLocation = ((TextBox)GridView1.Rows[i].FindControl("txtLocation")).Text;




try
                 {
                     const string strUpdate = "Update gvtest set status ='Y' WHERE mem_id = @mem_id and item_no=@v_item_no";
                     cmd.CommandType = CommandType.Text;
                     cmd.CommandText = strUpdate.ToString();
                     cmd.Parameters.Clear();




cmd.Parameters.AddWithValue("@mem_id", strID);
                  cmd.Parameters.AddWithValue("@item_no", v_item_no);
                  cmd.Connection = con;
                  con.Open();
                  cmd.ExecuteNonQuery();
              }
              catch (SqlException ex)
              {
                  string errorMsg = "Error in Updation";
                  errorMsg += ex.Message;
                  throw new Exception(errorMsg);
              }
              finally
              {
                  con.Close();
              }









留言:



更新错误。必须声明标量变量@v_item_no



任何人都可以识别错误并提供帮助吗?





Message:

Error in updation. Must declare the scalar variable "@v_item_no"

Can anyone identify the error and help?

推荐答案

cmd.Parameters.AddWithValue(@ item_no,v_item_no);



将@item_no更改为@v_item_no


$ b参数中缺少$ b v_
cmd.Parameters.AddWithValue("@item_no", v_item_no);

Change @item_no to @v_item_no

v_ is missing from the parameter


您的查询具有不同名称的参数。

Your query is having the parameter with different name.
Update gvtest set status ='Y' WHERE mem_id = @mem_id and item_no=@v_item_no



两个地方的参数名称应相同。

试试这个:


Parameter name should be same at both the places.
Try this:

cmd.Parameters.AddWithValue("@mem_id", strID);
cmd.Parameters.AddWithValue("@v_item_no", v_item_no);











--Amit






--Amit


是:

Yes:
const string strUpdate = "Update gvtest set status ='Y' WHERE mem_id = @mem_id and item_no=@v_item_no";
...
cmd.Parameters.AddWithValue("@item_no", v_item_no);

参数名称必须匹配:将两者的最后一行更改为:

The parameter names must match: change last line of the two to:

cmd.Parameters.AddWithValue("@v_item_no", v_item_no);


这篇关于声明标量变量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆