必须声明标量变量“@userName”

tongmux55 2007-10-23 09:47:19
StringBuilder sellog = new StringBuilder();
sellog.Append("select * from Userinfo ");
sellog.Append("where userName= @userName ");
OleDbParameter[] parameter ={
new OleDbParameter ("@userName",OleDbType.VarChar)};
parameter[0].Value = Usertxt.Text.Trim().ToString();

程序原来是用ole连接access数据库的,现在换成连接SQL,就会报必须声明标量变量“@userName”
请各位大哥看看是什么错误啊,在线等,急啊;
是不是他们传参的方式不同啊
...全文
1699 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
地海一刀 2010-01-22
  • 打赏
  • 举报
回复
在SQL Server 2005中
声明和赋值不能写在一起,否则保必须申明标量函数的错误
错误的语法:declare @codeLen int = LEN(@selfCode)
正确的语法:
declare @codeLen int
set @codeLen = LEN(@selfCode)
tongmux55 2008-02-18
  • 打赏
  • 举报
回复
传参的方式不同啊
Josion 2007-10-23
  • 打赏
  • 举报
回复
3楼正解!
tongmux55 2007-10-23
  • 打赏
  • 举报
回复
问题解决,就是将where userName= @userName 换成where userName=?即可
很高兴
沅江汐水 2007-10-23
  • 打赏
  • 举报
回复
把错误提示发出来看看啊

这个表面上是看不出来的哦
cyy1981 2007-10-23
  • 打赏
  • 举报
回复
parameter 要给oledbcommand

贴code出来看看
wuhan_dotnet 2007-10-23
  • 打赏
  • 举报
回复
肯定没加进去```
godling 2007-10-23
  • 打赏
  • 举报
回复
SqlParameter[] parameter ={
new SqlParameter("@userName",SqlDbType.VarChar)};
lovefootball 2007-10-23
  • 打赏
  • 举报
回复
parameter赋给sqlcommand了么?
苏陌Bubble 2007-10-23
  • 打赏
  • 举报
回复
new OleDbParameter ("userName",OleDbType.VarChar)}; ??
problem2050 2007-10-23
  • 打赏
  • 举报
回复
好像不能用这个关键字username,我原来用这个字段就出问题.

你换个试试user_name

111,111

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧