sql参数究竟怎么搞啊~~~~~~~~~~~?

nne998 2003-05-15 03:44:28
MyCommand.CommandText="select * from dbuser where xh='@aaa' and mm='@bbb'";
MyCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("@aaa",edUser.Text));
MyCommand.Parameters.Add(new System.Data.Odbc.OdbcParameter("@bbb",edPasswd.Text));


不行~~~~~~~
...全文
21 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
algo 2003-05-15
  • 打赏
  • 举报
回复
MyCommand.CommandText="select * from dbuser where xh='@aaa' and mm='@bbb'";
上面这行改为
MyCommand.CommandText="select * from dbuser where xh=? and mm=?";
把命名参数换成问号
nne998 2003-05-15
  • 打赏
  • 举报
回复
up
nne998 2003-05-15
  • 打赏
  • 举报
回复
The ODBC .NET Provider ---does not---- support named parameters for passing parameters to an SQL statement or a stored procedure called by an OdbcCommand when CommandType is set to Text. In this case, the question mark (?) placeholder must be used. For example:
SELECT * FROM Customers WHERE CustomerID = ?


~~~~~~~~~does not ???
nne998 2003-05-15
  • 打赏
  • 举报
回复
我觉得可能是odbc的问题,我用?做参数,象下面那样,就可以:
MyCommand.CommandText="select * from rsgl.rsk where xh=? and mm=? and zx='Y'";
MyCommand.Parameters.Add(new OdbcParameter()).Value=edUser.Text;
MyCommand.Parameters.Add(new OdbcParameter()).Value=edPasswd.Text;


~~~~为什么??
dalilei 2003-05-15
  • 打赏
  • 举报
回复
使用输入输出参数
Dim cn As New SqlConnection()
cn.ConnectionString = "server=kj009;uid=sa;pwd=;database=newchklist"
cn.Open()
Dim cmd As New SqlCommand()
cmd.Connection = cn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getserial"
Dim p As New SqlParameter()
p = cmd.Parameters.Add(New SqlParameter("@sort", SqlDbType.NVarChar, 15))
p.Direction = ParameterDirection.Input
p.Value = "qid"

Dim p1 As SqlParameter
p1 = cmd.Parameters.Add(New SqlParameter("@id", SqlDbType.VarChar, 10))
p1.Direction = ParameterDirection.Output

cmd.ExecuteNonQuery()
TextBox1.Text = p1.Value
slayersun 2003-05-15
  • 打赏
  • 举报
回复
where xh='@aaa' and mm='@bbb'
去掉单引号试试,不行的话报什么错?
nne998 2003-05-15
  • 打赏
  • 举报
回复
to liufan76(维他命) : 不行~~~~~
liufan76 2003-05-15
  • 打赏
  • 举报
回复
select * from dbuser where xh=@aaa and mm=@bbb

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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