【问题】其他信息: 必须声明标量变量 "@XXX"...

using Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility;

namespace DAL
{
public class CommodityDAL
{
public bool EditCM(CommodityModel cm)
{
string sql = @"insert into Commodity(CommodityName, SortID, CommodityPrice, IsDiscount, ReducedPrice) values(@Name,@ID,@Price,@Discount,@RPrice)";
SqlParameter[] ps = {
new SqlParameter("@Name",cm.CommodityName),
new SqlParameter("@ID",cm.SortID),
new SqlParameter("@Price",cm.CommodityPrice),
new SqlParameter("@Discount",cm.IsDiscount),
new SqlParameter("@RPrice",cm.ReducePrice)
};

        return SqlHelper.ExecuteNonQuery(sql) > 0;
    }

}

}

发生异常:
“System.Data.SqlClient.SqlException”类型的未经处理的异常在 System.Data.dll 中发生

其他信息: 必须声明标量变量 "@Name"。

请问给位大神,这是怎么回事?断点查看
cm.CommodityName
cm.SortID
cm.CommodityPrice
cm.IsDiscount
cm.ReducePrice
都有相应的值!
为什么就传不进去呢?图片说明图片说明

sql

1个回答

string sql = @"insert into Commodity(CommodityName, SortID, CommodityPrice, IsDiscount, ReducedPrice) values(@Name,@ID,@Price,@Discount,@RPrice)";

去掉字符串前面的@符号

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
必须声明标量变量 "@XXX"。
错误如题?具体情况是这样的:rn请看C#代码:rn[code=C#]rnusing (SqlConnection cn = db.conn())rnrn SqlCommand cmd = cn.CreateCommand();rn cmd.CommandText = @"INSERT INTO jc_WrongPaper ([userName],[libraryID],[mainPID],[lowerPID],[userAnswer])rn VALUESrn (@userName,@libraryID,@mainPID,@lowerPID,@userAnswer)";rn cmd.CommandType = CommandType.Text;rn cmd.Parameters.Add(new SqlParameter("@userName", wpM.userName));rn cmd.Parameters.Add(new SqlParameter("@libraryID",SqlDbType.Int));rn cmd.Parameters["@libraryID"].Value = wpM.libraryID;rn cmd.Parameters.Add(new SqlParameter("@mainPID", SqlDbType.Int));rn cmd.Parameters["@mainPID"].Value = wpM.mainPID;rn if (wpM.lowerPID != 0)//请注意这里 rn rn cmd.Parameters.Add(new SqlParameter("@lowerPID", SqlDbType.Int));rn cmd.Parameters["@lowerPID"].Value = wpM.lowerPID;rn rn cmd.Parameters.Add(new SqlParameter("@userAnswer", wpM.userAnswer));rn cn.Open();rn cmd.ExecuteNonQuery();rnrn[/code]rn说明:rn数据库中lowerPID这个字段是int型,可以为空,我原本想是如果传递过来的lowerPID为0,则这个字段不插入值,但是会报错,错误为:rn[b][color=#FF0000]必须声明标量变量 "@lowerPID"。[/color][/b]rn网上找了一下,应该是@lowerPID必须传值,有人推荐用字符串拼接方式来生成sql语句,但是我不想这样,不知道有没有解决办法,请高手赐教!!!rnrn[size=24px][b]如能解决,80%分数归你![/b][/size]
必须声明标量变量@XXX
在别人机器没有,在我机器出现。rn所有的保存都出现这个错误rn出现错误的地方 : obj.Save()
必须声明标量变量
string sqlConnect = @"server=SZX-MZT\mzt;database=mzt;uid=sa;pwd=asdfgh";rn SqlConnection conn = new SqlConnection(sqlConnect);rn conn.Open();rn //SqlCommand cmd = new SqlCommand("select * from Login where username='" + TextBox1.Text + "' and pwd='" + TextBox2.Text + "' ", conn);rn SqlCommand cmd = new SqlCommand("select * from Login where username=@UN and pwd=@PWD ", conn);rn SqlCommand pa = conn.CreateCommand();rn pa.Parameters.Add(new SqlParameter("UN",TextBox1.Text));rn pa.Parameters.Add(new SqlParameter("PWD", TextBox2.Text));rn SqlDataReader rdr = cmd.ExecuteReader();rn if (rdr.HasRows)rn rn Response.Redirect("查询.aspx");rn rn elsern rn Response.Write("retry");rn rn///提示必须声明标量变量@UN,怎么破?
必须声明标量变量@
[code=C#] SqlString = "SELECT Pub_Users.LogId,Obj_staff.StaffId,Obj_staff.StaffName,Pub_Roles.RoleName"rn + " FROM Pub_Users,Obj_staff,Pub_UserRole,Pub_Roles"rn + " WHERE Pub_Users.StaffId=Obj_staff.StaffId"rn + " and Pub_Users.LogId=Pub_UserRole.LogId"rn + " and Pub_UserRole.RoleId=Pub_Roles.RoleId"rn + " and Pub_Roles.RoleName LIKE '%'+@rrr+'%'";rn SqlParameter myParameter = new SqlParameter("@rrr", SqlDbType.VarChar);rn myParameter.Value = role;rn bh.AddParameter(myParameter);rn ds = bh.GetDataSet(SqlString); [/code]rnrn总是报这样的错,role是函数的参数,肯定有值
必须声明标量变量 "@"。
rn int sign = 0;rn bool inserted = false;rn rn Database db = DatabaseFactory.CreateDatabase(strStr);rn //DbConnection dbCon = db.CreateConnection();rn string sqlCommand="insert into uiRegister(vrLoginname,vrPwd,vrEmail,PK_intQuestion,vrAnswer)values"+rn "(@vrLoginname,@vrPwd,@vrEmail,@ PK_intQuestion,@vrAnswer)";rn DbCommand dc = db.GetSqlStringCommand(sqlCommand);rn //dbCon.Open();rn //DbTransaction dtransaction = dbCon.BeginTransaction();rn //dc.Transaction = dtransaction;rn db.AddInParameter(dc, "vrLoginname", DbType.String, vrLoginname);rn db.AddInParameter(dc, "vrPwd", DbType.String, vrPwd);rn db.AddInParameter(dc, "vrEmail", DbType.String, vrEmail);rn db.AddInParameter(dc, "PK_intQuestion", DbType.Int16, PK_intQuestion);rn db.AddInParameter(dc, "vrAnswer", DbType.String, vrAnswer);rn // dtransaction = new DbTransaction();rn rn //tryrn //rn sign = db.ExecuteNonQuery(dc);rn //dtransaction.Commit();rnrnrn //rnrnrn[color=#FF0000]以上代码会报错,必须声明标量变量@ 为什么?????????????????????[/color]
必须声明标量变量???
set ANSI_NULLS OFFrnset QUOTED_IDENTIFIER OFFrnGOrnALTER PROCEDURE [dbo].[z_Clienteligib_update]rnrn@creationtimestamp datetime,rn@user_id varchar(20),rn@survey_id varchar(50),rn@facility_id varchar(20),rn@eligibility_id varchar(20),rn@onfilecount varchar(20),rn@submitted varchar(20),rn@firstname varchar(50),rn@lastname varchar(50),rn@aliases varchar(255),rn@medrecnum datetime,rn@sd_id varchar(20)rnASrnrnGOrnBEGINrnupdate surveyrnset creationtimestamp=@creationtimestamp,user_id=@user_id,survey_id=@survey_id,facility_id=@facility_id,eligibility_id=@eligibility_id,onfilrnrnecount=@onfilecount,submitted=@submitted,firstname=@firstname,lastname=@lastname,aliases=@alrnrniases,medrecnum=@medrecnumrnwhere sd_id=@sd_idrnrnENDrn这个存储过程总是提示消息 137,级别 15,状态 2,第 3 行rn必须声明标量变量 "@creationtimestamp"。rnrn求救啊
必须声明标量变量的问题
在存储过程中,部分代码如下rn[code=sql]rn--根据系统ID取得要查询的表名和字段名rnselect @TableName=TableName,@ColumnName=ColumnName from #SysTableName where SystemId=@SystemIdrndeclare @tName nvarchar(1000)rn--拼接执行语句rnexec(N'select @tName=NodeName from '+@TableName+ ' where '+@ColumnName+'='+@tHierarchyId)rn[/code]rnrn报的错为 必须声明标量变量 "@tName"。 rn但是我在拼接前声明了的
"必须声明标量变量"的问题
[code=SQL] conn.Open();rnrn [color=#FF0000]SqlCommand cmd1 = new SqlCommand("select count(*) from GLXT where BH = @BH", conn);[/color]rn int count = Convert.ToInt32(cmd1.ExecuteScalar());rnrn if (count == 0)rn rn string sql = "insert into GLXT (BH,XB,NL) values (@BH,@XB,@NL)";rn cmd = new SqlCommand(sql, conn);rn rn elsern rn string sql = "update GLXT set XB = @XB,NL = @NL where BH = @BH";rn cmd = new SqlCommand(sql, conn);rn rnrn SqlParameter[] parameters = new SqlParameter[3];rn parameters[0] = new SqlParameter();rn parameters[0].ParameterName = "@BH";rn parameters[0].SqlDbType = SqlDbType.VarChar;rnrn parameters[1] = new SqlParameter();rn parameters[1].ParameterName = "@XB";rn parameters[1].SqlDbType = SqlDbType.VarChar;rnrn parameters[2] = new SqlParameter();rn parameters[2].ParameterName = "@NL";rn parameters[2].SqlDbType = SqlDbType.VarChar;rnrn for (int i = 0; i < parameters.Length; i++)rn rn cmd.Parameters.Add(parameters[i]);rn [/code]rnrn提示:必须声明标量变量 "@BH"。
必须声明标量变量“@userName”
StringBuilder sellog = new StringBuilder();rnsellog.Append("select * from Userinfo ");rnsellog.Append("where userName= @userName ");rnOleDbParameter[] parameter =rn new OleDbParameter ("@userName",OleDbType.VarChar);rnparameter[0].Value = Usertxt.Text.Trim().ToString();rnrn 程序原来是用ole连接access数据库的,现在换成连接SQL,就会报必须声明标量变量“@userName”rn请各位大哥看看是什么错误啊,在线等,急啊;rn是不是他们传参的方式不同啊rn
必须声明标量变量 @DataBase_ID
[code=SQL]rnalter Procedure [dbo].[GetProtypeList]rn @DataBase_InsertUser bigint,rn @DataBase_ID bigintrnASrn DECLARE @DataBase_Address varchar(50)rn DECLARE @DataBase_LoginName varchar(50)rn DECLARE @DataBase_DBS varchar(50)rn DECLARE @DataBase_Table varchar(50)rn DECLARE @DataBase_PassWord varchar(50)rnBEGINrn rn select @DataBase_Address=[DataBase_Address],@DataBase_LoginName=[DataBase_LoginName],rn @DataBase_DBS=[DataBase_DBS],@DataBase_Table=[DataBase_Table],rn @DataBase_PassWord=[DataBase_PassWord] rn FROM DataBaseInfo WHERE [DataBase_DelFlag]=0 rn AND [DataBase_ID]=@DataBase_IDrnrn declare @s varchar(8000)rn set @s='INSERT INTO ProtypeInfo SELECT rn [PT_ID],@DataBase_ID,[PT_Name],'',[PT_Level],[PT_ParentID],[PT_Unit],[PT_IsShow],[PT_IsGuide],[PT_IsIndex],rn [PT_FilterAttribute],[PT_PriceInterval],[PT_StylePath],[PT_KeyWord],[PT_Describe],[PT_Properties],[PT_IsEndType],rn [PT_DelFlag],getdate(),@DataBase_InsertUser,[PT_OrderNum],[PT_IsTrue],[PT_S1],[PT_S2],[PT_S3],[PT_S4],[PT_S5]rn FROM rn DB.PDB.DBO.ProtypeInforn OPENROWSET rn (''sqloledc'','+@DataBase_Address+';'+@DataBase_LoginName+';'+@DataBase_PassWord+','+@DataBase_DBS+'.DBO.'+@DataBase_Table+''')'rn exec (@s)rnEND[/code]rn已经完成命令rn但是在调用此存储过程时,却老提示必须声明标量变量 @DataBase_ID?这是为什么呢?请帮忙rn调用方法如下rn[code=C#]rnpublic Boolean UA_DataBaseInfo_GetProtypeInfo(Int64 DataBase_ID, Int64 DataBase_InsertUser)rn rn DbCommand dbcmd = db.GetStoredProcCommand("GetProtypeList");rn db.AddInParameter(dbcmd, "@DataBase_ID", DbType.Int64, DataBase_ID);rn db.AddInParameter(dbcmd, "@DataBase_InsertUser", DbType.Int64, DataBase_InsertUser);rn Int64 result = 0;rn tryrn rn result = db.ExecuteNonQuery(dbcmd);rn rn catch (Exception ex)rn rn throw ex;rn rn return result > 0 ? true : false;rn rn[/code]
存储过程——必须声明标量变量
用存储过程导数据,直接使用下面语句就可以执行rnrn[code=sql]Bulk Insert TempTable FROM 'e:\123.csv' WITH(FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')[/code]rnrn我把路径改成参数@FilePath ,就会提示“必须声明标量变量@FilePath” 应该怎么改?rnrn[code=sql]SET @ImpSQLstr= 'Bulk Insert #TempTable1 FROM '+ @FilePath +'; WITH (FIELDTERMINATOR ='','',ROWTERMINATOR = ''\n'')'rnExec (@ImpSQLstr) [/code]rnrn本来还提示With 前必须加分号,我加了不知道对不对
必须声明标量变量 "@id"。
//删除数据rn public int DelAdmin(int sId)rn rn OleDbConnection myconn = new OleDbConnection(DB.conn);rn OleDbCommand mycmd = new OleDbCommand("delete from baoming where id =@id", myconn);rn mycmd.Parameters.Add("@id", sId);rn int nResult = -1;rn tryrn rn myconn.Open();rn nResult = mycmd.ExecuteNonQuery();rn rn catch (OleDbException ex)rn rn throw new Exception(ex.Message, ex);rn rn finallyrn rn myconn.Close();rn rn return nResult;rn rnrnsId肯定传过来值了,但是老报错rnrnrnrnrn必须声明标量变量 "@id"。 rn说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.OleDb.OleDbException: 必须声明标量变量 "@@id"。rnrn源错误: rnrnrnrnrnrn行 94: rn行 95: myconn.Open();rn行 96: nResult = mycmd.ExecuteNonQuery();rn行 97: rn行 98: catch (OleDbException ex) rn
必须声明标量变量 "@name"。
声明了一个变量 ''declare @name varchar(8)'',执行赋值语句 '' select @name = '李文才' '' 的时候出了这个错误 ''必须声明标量变量 "@name"。 ''
必须声明标量变量 wa1
麻烦看下,报错 必须声明标量变量 wa1 rn这是存储过程 rn[code=sql]rnset ANSI_NULLS ON rnset QUOTED_IDENTIFIER ON rngo rnrnrnrnrnALTER proc [dbo].[sale_score] rn@wa1 varchar(1000) -- 用来传递where条件 rnas rnbegin rndeclare @tsql1 varchar(2000), rn@tsql2 varchar(2000), rn@tsql3 varchar(2000), rn@tsql4 varchar(2000), rn@tsql5 varchar(6000) rnrn rnselect @tsql1=isnull(@tsql1+',','')+'['+business_name+']', rn @tsql2=isnull(@tsql2+',','')+'isnull(['+business_name+'],0) '''+business_name+''' ', rn @tsql3=isnull(@tsql3+'+','')+'isnull(['+business_name+'],0)', rn @tsql4=isnull(@tsql4+',','')+'sum(case when c.business_name='''+business_name+''' then a.sale_jifen else 0 end) ' rn from Business rn order by business_name desc rn rnselect @tsql5='select replace(branch_name,''部门'','''') ''部门'','+@tsql2+','+@tsql3+' ''合计'' ' rn +' from (select a.sale_branch,a.sale_jifen,c.business_name,d.branch_name ' rn +' from salemx a ' rn +' inner join ProductType b on a.sale_typeid=b.type_id ' rn +' inner join Business c on b.type_bizid=c.business_id ' rn +' inner join branch d on d.branch_num=a.sale_branch ' rn +' where @wa1 ) t ' rn +' pivot(sum(sale_jifen) for business_name in('+@tsql1+')) u ' rn +' union all ' rn +' select ''合计'','+@tsql4+',sum(a.sale_jifen) ' rn +' from salemx a ' rn +' inner join ProductType b on a.sale_typeid=b.type_id ' rn +' inner join Business c on b.type_bizid=c.business_id ' rn +' inner join branch d on d.branch_num=a.sale_branch ' rn +' where @wa1 ' rnexec(@tsql5) rnend rnrn[/code]rnrnrn这是C# rnrnrn[code=csharp]rnrn DataSet ds = new DataSet(); rn SqlParameter para = new SqlParameter("@wa1", SqlDbType.VarChar, 1000); rn para.Direction = ParameterDirection.Input; rn para.Value = HWhere.Value.ToString(); //hwwhere是条件 where biz='21' or biz='23' rn SqlParameter[] paras = para ; rnrn ds = DAL.DBHelp.RunProcedure("dbo.sale_score",paras ,"tt",30); rn DataTable dsLog = ds.Tables[0]; rn rn rnrnrn RpBook.DataSource = dsLog; rn RpBook.DataBind(); rnrn[/code]rnrnrn这是 dbhelp类 rnrn[code=csharp]rnrn/// rn /// 执行存储过程,返回dataset rn /// rn /// 存储过程名 rn /// 存储过程参数 rn /// dataset结果中的表名 rn /// 超时时间 rn /// DataSet rn public static DataSet RunProcedure(string storedProcName,IDataParameter[] parameters,string tableName,int Times ) rn rn using (SqlConnection connection = new SqlConnection(ConnectionString)) rn rn DataSet ScoreSet= new DataSet (); rn connection.Open(); rn SqlDataAdapter sqlDA=new SqlDataAdapter(); rn sqlDA.SelectCommand=BuildQueryCommand(connection ,storedProcName,parameters ); rn Times = 30; rn sqlDA.SelectCommand.CommandTimeout=Times; rn sqlDA.Fill(ScoreSet ,tableName ); rn connection.Close(); rn return ScoreSet; rn rn rnrnrn rnrnrn /// rn ///构建sqlcommand对象 rn /// rn ///数据库连接字符串 rn ///存储过程名 rn ///存储过程参数 rn ///sqlcommand rn private static SqlCommand BuildQueryCommand(SqlConnection connection,string storedProcName,IDataParameter[] parameters) rn rn SqlCommand command=new SqlCommand (storedProcName,connection ); rn command.CommandType=CommandType.StoredProcedure ; rn if (parameters !=null && parameters.Length>0) rn rn foreach (SqlParameter parameter in parameters ) rn rn if (parameter !=null) rn rn //未赋值的参数,赋值为dbnull.value rn if ((parameter.Direction==ParameterDirection.Input || parameter.Direction == ParameterDirection.Input ) rn && (parameter.Value ==null )) rn rn parameter.Value=DBNull.Value; rn rn command.Parameters.Add(parameter); rn rn rn rn return command; rn rn[/code]
为什么:必须声明标量变量?
我的一个过程rncreate procedure crmdbo.gzzq_brokerjjrfyjshzb_cxrn @client_branch_no BranchNo , rn @branch_no varchar(200) , rn @begin_date IntDate , rn @end_date IntDate , rn @broker_account BrokerAccount , rnasrnrn---这一段作怪,为A段rndeclare @sql varchar(8000)rn select @sql = 'create table #tempshow(month_id int not null, branch_no varchar(8) not null, branch_no_shou varchar(8) not null,' +rn 'fare1 numeric(19,2) not null, branch_no_fu varchar(8) not null, fare2 numeric(19,2) not null)'rnexec(@sql) rngo rn--这一段做怪 rnrnif object_id( 'tempdb..#temp') is not null rn drop table #temprnselect distinct month_id, branch_no into #temp from crmcurrent.crmdbo.gzzq_brokerjjrfyjsmxbrnwhere month_id between @begin_date/100 and @end_date/100rn and (@branch_no = '' or rtrim(branch_no)= rtrim(@branch_no))rn order by month_id, branch_nornrnrn一直 提示 错误:rn消息 137,级别 15,状态 2,第 7 行rn必须声明标量变量 "@begin_date"。rn消息 137,级别 15,状态 2,第 70 行rn必须声明标量变量 "@branch_no"。rn消息 137,级别 15,状态 2,第 73 行rn必须声明标量变量 "@branch_no"。rnrn上面提示的全部是过程自带的参数,就是因为A段存在(这段语法没问题的),提示这个错误,没有A断就正常。rnrn我的疑问:难道过程里面不能create table?为什么加上那段,过程变量就失效了呢???rnrn
必须声明标量变量 "@zone"
SqlDataSource3.SelectCommand = "SELECT * FROM [priceInfo] where zone= @zone";rn SqlDataSource3.SelectParameters.Add("@zone", "String");rn SqlDataSource3.SelectParameters[0].DefaultValue = "二厂";rnrn错误提示:必须声明标量变量 "@zone"。 rn帮忙改一下~
必须声明标量变量..怎么回事
declare @a decimal(18, 0)rnselect @a=price from jiage where name='生爆肚尖'rn为什么是这样的错误消息rn 137,级别 15,状态 1,第 2 行rn必须声明标量变量 "@a"。rn
必须声明标量变量 的错误
直接运行 select [报告模板-PSI] from 客户汇总对比 where 客户='CD3' 可以得出正确的结果rn但是运行rn[code=sql]rn declare @sql varchar(max)rn declare @inspection_type nvarchar(255)rn declare @client_name nvarchar(255)rn declare @report_model nvarchar(255)rn set @sql=''rn set @inspection_type='PSI'rn set @client_name='CD3'rn set @report_model=''rn select @sql = 'select @report_model=[报告模板-'+@inspection_type + '] from 客户汇总对比 where 客户='+@client_namern exec (@sql)rn print @report_modelrn[/code]rn却报错rn消息 137,级别 15,状态 1,第 1 行rn必须声明标量变量 "@report_model"。rn请给与指导,非常感谢!
必须声明标量变量 "@regionCompanyorder"。
我做的一个条件查询,可是一触发查询条件就报着个错,以下是我写的代码:rn private void Parse(AgentInfoSearchWhere search, ref string cmdText, ref List cmdParams)rn rn if (!string.IsNullOrEmpty(search.AgentID))rn rn cmdText += " and AgentID like '%'+@agentID+'%'";rn cmdParams.Add(dbUtil.BuildInParameter("@agentID", search.AgentID));rn rn if (!string.IsNullOrEmpty(search.AgentName))rn rn cmdText += " and AgentName like '%'+@agentName+'%'";rn cmdParams.Add(dbUtil.BuildInParameter("@agentName", search.AgentName));rn rn if (search.RegionId.HasValue)rn rn if (string.IsNullOrEmpty(search.UserCode))rn rn cmdText += " and (RegionId=@region or IsHQ=1)";rn cmdParams.Add(dbUtil.BuildInParameter("@region", search.RegionId));rn rn elsern rn cmdText += " and RegionId=@region";rn cmdParams.Add(dbUtil.BuildInParameter("@region", search.RegionId));rn rn rn if (search.ManageRegionID.HasValue)rn rn if (string.IsNullOrEmpty(search.UserCode))rn rn cmdText += " and (ManageRegionID=@regionCompany or IsHQ=1)";rn cmdParams.Add(dbUtil.BuildInParameter("@regionCompany", search.ManageRegionID));rn rn elsern rn cmdText += " and ManageRegionID=@regionCompany";rn cmdParams.Add(dbUtil.BuildInParameter("@regionCompany", search.ManageRegionID));rn rn rn else if (!string.IsNullOrEmpty(search.UserCode))rn rn cmdText += " and (ManageRegionID is null or ManageRegionID in (select ManageRegionID from UserManageRegion where UserCode=@userCode1))";rn cmdParams.Add(dbUtil.BuildInParameter("@userCode1", search.UserCode));rn rn rn麻烦大家帮忙看看有什么错误啊?
必须声明标量变量 "@User_Name"。
public static DataTable Selectlist(string user_Name,string user_ID)rn rn List list = new List();rn string sql = "select * from U_USERINFO where User_Name = @User_Name or User_ID = @User_ID ";rnrn SqlParameter[] par = new SqlParameter[] rn new SqlParameter("@User_Name",user_Name),rn new SqlParameter("@User_ID",user_ID)rn ;rn DataTable dt = DBHelper.ExcuteDataTable(sql, CommandType.Text, par);rnrnrn return dt;rn
错误:必须声明标量变量
我在gridview中添加的编辑和删除按钮,与gridview相连的sqldatasource控件做了下面的设置,rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn当我使用gridview的删除或者编辑功能时,总是提示错误:必须声明标量变量 "@wlno"。 rn我应该怎么修改啊?
必须声明标量变量 "@bkname"。
CREATE PROCEDURE wx @bknamernAS rnIF (SELECT 维修费用 FROM cl WHERE 车牌号=@bkname) BETWEEN (100,2000)rn RETURN 1rnELSE rn RETURN 2rnGOrnrn
必须声明标量变量 "@tt"
create function [dbo].[uf_getchima](@warecode nchar(20)) rnreturns nvarchar(500) rnas rnbegin rndeclare @tt table (size varchar)rndeclare @str nvarchar(500) rnset @str='' rninsert into @tt(size) select showsize.size from saware_size,showsize with(nolock) where saware_size.warecode=@warecode and saware_size.size=showsize.size order by showsize.showrnselect @str=ltrim(rtrim(@str))+ltrim(rtrim(@tt.size))+',' from @tt rnreturn @str rnendrngornrnrn提示:必须声明标量变量 "@tt"
必须声明标量变量 "@indextable"。
declare @indextable table(id int identity(1,1),nid int)rn set rowcount @endIndexrn insert into @indextable(nid) select ID from Info order by ID descrnrn set @sqlStr=@sqlStr + 'select * from Info O, ' + @indextable +' t where O.ID=t.nidrn and t.id between ' + @startIndex + ' and ' + @endIndexrnrn print @sqlStrrnrn请问如上代码,明明已经申明了@indextable ,为什么还报错,要申明标量变量 "@indextable"。呢?rn 请大家帮帮忙,谢谢了!
必须声明标量变量 "@CourseID"。
[code=C#] int a = 1;rn Params1[0] = DB.MakeInParam("@CourseID", SqlDbType.Int, 4, a); //试卷编号 rn DataSet ds1 = DB.GetDataSet("Proc_PaperDetail",Params1);rn GridView2.DataSource = ds1;rn GridView2.DataBind();rnrn SqlParameter[] Params2 = new SqlParameter[1];rn int b = 2;rn Params2[0] = DB.MakeInParam("@CourseID", SqlDbType.Int, 4, b); //试卷编号 rn DataSet ds2 = DB.GetDataSet("Proc_PaperDetail", Params2);rn GridView5.DataSource = ds2;[/code]rnrn存储过程代码:rn[code=SQL]set ANSI_NULLS ONrnset QUOTED_IDENTIFIER ONrnGOrnrnrnrnALTER PROCEDURE [dbo].[Proc_PaperDetail]rn (@CourseID [int])rnASrnbegin rn declare @sql nvarchar(1000)rnif @CourseID=1rn begin rn set @sql='select * from MultiProblem where CourseID=@CourseID'rn exec sp_executesql @sql rn endrnelse if @CourseID=2rn begin rn set @sql='select * from MultiProblem where CourseID=@CourseID'rn exec sp_executesql @sql rn endrnelse if @CourseID=3rn begin rn set @sql='select * from MultiProblem where CourseID=@CourseID'rn exec sp_executesql @sql rn endrnelse if @CourseID=4rn begin rn set @sql='select * from MultiProblem where CourseID=@CourseID'rn exec sp_executesql @sql rn endrnelsern begin rn set @sql='select * from MultiProblem where CourseID=@CourseID'rn exec sp_executesql @sql rn endrnend[/code]
必须声明标量变量 \"@id0\"
[code=csharp] sql = "delete indexsetting where istaid in(";rn SqlParameter[] opt = new SqlParameter[id.Length];rn for (int i = 0; i < id.Length; i++)rn rn string str = "@id" + i + ",";rn sql += str;rn opt[i] = new SqlParameter(str, id[i]);rn rn sql = sql.Substring(0, sql.Length - 1) + ")";[/code]想多条删除,不用存储过程.传入的是ID.报错如标题.
必须声明标量变量@khdm
string sql = "update dtMT发票开单表 set 发票开单号=@fpksdID,客户代码=@khdm,增值票金额=@bczhpkpje,运输票金额=@bcyspkpje,票面金额=@pmje,日期=@rq,经办人=@jbr,增值票备注=@zhpbz,运输票备注=@yspbz,门岗人员=@mgry, 业务员=@ywy";rnrnrn谁帮我看看sql语句对吗
必须声明标量变量 "@regionand"。
我的存储过程里并未声明这个参数,后台方法里也没有这个参数,为什么还报这个错呢?麻烦各位帮忙看一下!
必须声明标量变量 "@TaskSend"。
[code=C#] string commandName = "Pr_Plan_TaskSend_GetTaskTypeCodeFromTaskSendID";rn #region Parametersrn SqlParameter[] parms = SqlHelperParameterCache.GetCachedParameterSet(ConnectionString.OmsRead, commandName);rn if (parms == null)rn rn parms = new SqlParameter[] rn new SqlParameter("@TaskSendID", SqlDbType.Int),rn new SqlParameter("@TaskTypeCode", SqlDbType.VarChar,10)rnrn ;rn parms[0].Value = TaskSendID;rn parms[1].Direction = ParameterDirection.Output;rn parms[1].Value = "";rn SqlHelperParameterCache.CacheParameterSet(ConnectionString.OmsRead, commandName, parms);rn rnrn rn #endregionrn using (SqlDataReader dataReader = SqlHelper.ExecuteReader(ConnectionString.OmsRead, CommandType.StoredProcedure, commandName, parms)) ///这句报的错rn[/code]rn[code=SQL]rnALTER PROCEDURE [dbo].[Pr_Plan_TaskSend_GetTaskTypeCodeFromTaskSendID]rn (@TaskSendID int, @TaskTypeCode VARCHAR(4) output)[/code]rnrn
"必须声明标量变量 \"@cwUser\"。"
[code=csharp] sql = string.Format(@"rn update 0 set iscw =2,cwUser=@cwUser,cwTime = getdate() rn where id=1 and isApply=0rn ", TableName, id, iscw, isApply);rn [/code]rn求原因
必须声明标量变量 "@UserID"。
//添加rn public int Create(Order order)rn rn oConn conn = new oConn();rn string oInsert = "INSERT INTO [Tiens_Order] (UserID,ProCount,ProPrice,ProName,BeginTime,EndTime,TrafficPrice,Location,Addon) VALUES (@UserID,@ProCount,@ProPrice,@ProName,@BeginTime,@EndTime,@TrafficPrice,@Location,@Addon)";rn OleDbCommand oCommand = new OleDbCommand(oInsert, conn.iConn);rn oCommand.Parameters.Add("@UserID", OleDbType.Integer, 10);rn oCommand.Parameters.Add("@ProCount",OleDbType.Integer,10);rn oCommand.Parameters.Add("@ProPrice", OleDbType.Integer, 10);rn oCommand.Parameters.Add("@ProName",OleDbType.VarChar,20);rn oCommand.Parameters.Add("@BeginTime",OleDbType.Date);rn oCommand.Parameters.Add("@EndTime", OleDbType.Date);rn oCommand.Parameters.Add("@TrafficPrice", OleDbType.Integer, 10);rn oCommand.Parameters.Add("@Location", OleDbType.VarChar, 30);rn oCommand.Parameters.Add("@Addon", OleDbType.VarChar, 200);rnrn int id = 0;rn tryrn rn oCommand.Connection.Open();rn id = oCommand.ExecuteNonQuery();rn return id;rn rn catch (Exception exception)rn rn throw exception;rn rn finallyrn //必须声明标量变量 "@UserID"。rn oCommand.Connection.Close();rn rn rnrn
必须声明标量变量 \"@Proname\
protected void Button1_Click(object sender, EventArgs e)rn rn //从窗体中获取值rn string name, id, num, price, sum;rn name = ProName.Text;rn id = ProID.Text;rn num = ProNum.Text;rn price = ProPrice.Text;rn sum = ProSum.Text;rnrn string sqlstring = "Server=localhost;uid=sa;pwd=2613000;database=Stock";rnrn System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlstring);rnrn conn.Open();rnrnrn rn string insertCommand = "insert into 采购单(采购单号,产品名称,库存数量,成本价格)values(@id,@name,@num,@price)";rnrn rn System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(insertCommand, conn);rn //执行语句rn cmd.ExecuteNonQuery();rn //关闭连接rn conn.Close();rn Response.Write(" ");rn rnrnrn以上语句出现问题:rnrn用户代码未处理 System.Data.SqlClient.SqlExceptionrn Message="必须声明标量变量 \"@Proname\"。"rnrn请问如何声明标量变量??怎么改,我在网上查了看不大明白??rn谢谢先~rn
必须声明标量变量 "@tid"。
StringBuilder strSql = new StringBuilder();rn strSql.Append("select * from topic ");rn strSql.Append("where topicid=@tid");rnrn SqlParameter[] parameters = rn new SqlParameter("@tid",SqlDbType.Int,4),rn ;rn parameters[0].Value = 18;rnrnrn为什么老是报错:必须声明标量变量 "@tid"。rnrn谢谢
必须声明标量变量@T
有以下代码在Ctrl+F5时老是提示‘必须声明标量变量@T’,麻烦帮看下到底是哪里错了rn[code=SQL]rndeclare @Sql nvarchar(500)rndeclare @SysOrderNo intrndeclare @ShortName varchar(30),@Spec varchar(30),@Spec1 varchar(30),@Spec2 varchar(30),@Spec3 varchar(30),@Spec4 varchar(30)rndeclare @DataBaseName varchar(30)rndeclare @T table (Row int identity(1,1) not null,rn ShortName varchar(30) null,rn Spec varchar(30) null,rn Spec1 varchar(30) null,rn Spec2 varchar(30) null,rn Spec3 varchar(30) null,rn Spec4 varchar(30) null,rn primary key (Row)rn)rnSet @DataBaseName='FYData'rnSet @SysOrderNo=5rnSet @Sql='insert into @T Select ShortName,Spec,Spec1,Spec2,Spec3,Spec4 From '+@DataBaseName+'.dbo.ORDERDETAIL '+' Where SysOrderNo='+cast(@SysOrderNo as varchar(10))rnexec sp_executesql @Sql,N'@ShortName varchar(30) output,@Spec varchar(30) output,@Spec1 varchar(30) output,@Spec2 varchar(30) output,@Spec3 varchar(30) output,@Spec4 varchar(30) output,@T table output',@ShortName output,@Spec output,@Spec1 output,@Spec2 output,@Spec3 output,@Spec4 output,@T outputrnSelect * From @Trn[/code]rnrn消息框里提示错出在exec那一句
必须声明标量变量 "@IfConcel"
我找了半天,没有找到我没有声明的变量啊,只能求助了,断点也看不出来哪里有问题。rn我的代码如下rn[code=csharp]rnStringBuilder strSql = new StringBuilder();rn strSql.Append("insert into YyInfo(");rn strSql.Append("IfConcel,SPID,CgDay,CgTime,PeopNum,UnitName,AddressID,YyName,YyPhoneNum,UserID");rn strSql.Append(") values (");rn strSql.Append("@IfConcel,@SPID,@CgDay,@CgTime,@PeopNum,@UnitName,@AddressID,@YyName,@YyPhoneNum,@UserID");rn strSql.Append(") ");rn strSql.Append(";");rn //strSql.Append(";select @@IDENTITY");rn SqlParameter[] parameters = rn new SqlParameter("@IfConcel", SqlDbType.Int,4) , rn new SqlParameter("@SPID", SqlDbType.Int,4) , rn new SqlParameter("@CgDay", SqlDbType.DateTime) , rn new SqlParameter("@CgTime", SqlDbType.Char,20) , rn new SqlParameter("@PeopNum", SqlDbType.Int,4) , rn new SqlParameter("@UnitName", SqlDbType.Char,50) , rn new SqlParameter("@AddressID", SqlDbType.Int,4) , rn new SqlParameter("@YyName", SqlDbType.Char,50) , rn new SqlParameter("@YyPhoneNum", SqlDbType.Char,20) , rn new SqlParameter("@UserID", SqlDbType.Int,4) rn rn ;rnrn parameters[0].Value = model.IfConcel;rn parameters[1].Value = model.SPID;rn parameters[2].Value = model.CgDay;rn parameters[3].Value = model.CgTime;rn parameters[4].Value = model.PeopNum;rn parameters[5].Value = model.UnitName;rn parameters[6].Value = model.AddressID;rn parameters[7].Value = model.YyName;rn parameters[8].Value = model.YyPhoneNum;rn parameters[9].Value = model.UserID;rnrn object obj = SQLHelper.GetSingle(strSql.ToString(), parameters);rn if (obj == null)rn rn return 0;rn rn elsern rnrn return Convert.ToInt32(obj);rnrn rn[/code]
必须声明标量变量 "@sql"。
declare @sql varchar(8000),rn @i int ,rn @id varchar(50)rnset @i=0 rnset @id='XJD20120904000002'rnset @sql= 'select m.MaterielName ' rnselect @i=@i+1,@sql=@sql+ ',sum(case s.SupplierName rn when cast( ' +SupplierName+ ' as varchar(100)) then num else 0 end) [action '+cast(@i as varchar(50))+ '] ' rnfrom (select distinct SupplierName from dbo.TBA_Supplier) tem rnselect @sql=@sql+ 'from TPurc_RatioPrice as t,rn TPurc_EnquiryList as l,rn TBA_Supplier as s,rn TBA_Materiel as mrn where t.EnquiryListNo=l.EnquiryListNo andrn t.SupplierID=s.SupplierID and rn l.MaterielCode=m.MaterielCode andrn l.EnquiryNo='+@id+'rn group by m.MaterielName '
必须声明标量变量 "@**"的疑难问题!
代码如下:rnusing (SqlConnection conn = new SqlConnection(@"Persist Security Info=False;Integrated Security=SSPI;Initial Catalog=BYSJ;server=(local)"))rn rn conn.Open();rn using (SqlCommand cmd = new SqlCommand())rn rn cmd.CommandText = "select * from BookInformation where BookStuNum=@StuNum";rn cmd.Parameters.Add(new SqlParameter("StuNum", label10.Text));rn SqlDataAdapter adapter = new SqlDataAdapter(cmd.CommandText ,conn);rn DataSet dataset = new DataSet();rn adapter.Fill(dataset, "BookInformation");rn adapter.FillSchema(dataset, SchemaType.Source, "BookInformation");rn DataTable table = dataset.Tables["BookInformation"];rn dataGridView1.DataSource = dataset.Tables["BookInformation"];rnrnrnrn rn rnrn请问下这个代码为什么会在 adapter.Fill(dataset, "BookInformation");这里报错,说必须声明标量变量 "@StuNum"。rn但是如果不用参数化查询,而是以实际字符代替"@StuNum"却能查询成功,这是为什么?请指正!
必须声明标量变量 "@Id"的问题
[code=SQL]rndeclare @Id intrndeclare @tb varchar(3000)rndeclare @sql2 varchar(3000)rn--select @Id=Count(R.Id) from ReturnFix R, CoLocal C where C.Id=R.CoLocId and C.Id=(select top 1 id from Colocal where UserNameCo=@UserName)rnset @tb='i.ProductId=1 and b.brandid=44'rnrnset @sql2 = ' select @Id=count(distinct itemid)rnfrom Item i,Item_Parameter ip, Item_Parameter_Value ipv, Brand b, co crnwhere I.Status=''上'' and i.itemid=ipv.itemid and B.BrandId=i.BrandId and ipv.ParameterId=ip.ParameterId and c.itemid=i.itemid and 'rnrnset @sql2 = @sql2 + @tbrnrnexec (@sql2)rnprint @sql2rn[/code]rnrnprint 后得出:rnrn消息 137,级别 15,状态 1,第 1 行rn必须声明标量变量 "@Id"。rn select @Id=count(distinct itemid)rnfrom Item i,Item_Parameter ip, Item_Parameter_Value ipv, Brand b, co crnwhere I.Status='上' and i.itemid=ipv.itemid and B.BrandId=i.BrandId and ipv.ParameterId=ip.ParameterId and c.itemid=i.itemid and i.ProductId=1 and b.brandid=44rnrn可我都声明@Id变量了啊rn我是想得出itemid的个数?问题出在哪?rn
必须声明标量变量@ContentId 的问题
从前页用querystring 传入了contentid rn然后在新页面查看数据 rnrn代码如下[code=C#]rnint curPage = Convert.ToInt32(lblPageOnly.Text);rnrn SqlConnection con = new SqlConnection("server=.;database=TestOL;uid=sa;pwd=sa;");rn string sql = "SELECT ContentId, Question, Answer, AnswerA, AnswerB, AnswerD, AnswerC FROM Questions WHERE ContentId =@ContentId";rn SqlCommand cmd = new SqlCommand(sql, con);rn SqlDataAdapter da = new SqlDataAdapter(cmd);rn DataSet ds = new DataSet();rn con.Open();rn da.Fill(ds);[/code]rnrn但是在da.Fill(ds);这里老是出错 说是必须声明标量变量@ContentId rn请问应该怎么做
SQL拼接问题 必须声明标量变量
[code=SQL]DECLARE @sql varchar(1000)rnDECLARE @state intrnSET @state =1rnSET @sql='SELECT BusID,COUNT(1) 总访问量,UV = SUM(UV), IP = COUNT(DISTINCT ip) FROM (rnSELECT * FROM ADCount100603 union all select * from ADCount100605 union all select * from ADCount100611 rn ) t rn where rn state=@state OR @state IS NULL AND uv=1rn GROUP BY BusID rn ORDER BY 1 asc, 2 DESC, 3 DESC'rnexec(@sql)[/code]rnrn消息 137,级别 15,状态 2,第 5 行rn必须声明标量变量 "@state"。rnrnrn我知道是@state 变量的作用域的权限问题,有其他办法 可以判断 @state变量是否为空吗?
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件