参数化连接的问题?

eaqpi 2011-01-16 02:30:34

dim SqlStr="select * from [User] where 用户名= '@用户名'"
dim Conn as new sqlconnection
dim ds as new dataset
usering conn as new sqlconnection(MyData.conStr)
try
conn.open()
dim cmd as new sqlcommand(SQLstr,conn)
cmd.parameters.addwithvalue("@用户名",UserName)
cmd.commandtext =sqlstr
dim da as new sqldataadapter(SqlStr,conn)
da.fill(ds)
'do....
cathch ex as exception
debug.pring(ex.tostring)
finally
conn.close()
end try


在 运行的时候发现,参数没有被替换。
sqlstr连接字符串还是select * from [User] where 用户名= '@用户名'
是哪里错了?
...全文
50 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
eaqpi 2011-01-16
  • 打赏
  • 举报
回复
测试成功了,单步的时候那个值并不会被替换。CONSOLE.WRITE 出了的句子 是错的.....
wuyq11 2011-01-16
  • 打赏
  • 举报
回复
Dim sql As String = "insert into Tb(title) values(@title)"
Dim com As New SqlCommand(sql, MyConn)
com.Parameters.AddWithValue("@title", title)
com.ExecuteNonQuery()
没问题
wuyq11 2011-01-16
  • 打赏
  • 举报
回复
dim SqlStr="select * from [User] where 用户名= @用户名"
eaqpi 2011-01-16
  • 打赏
  • 举报
回复
没单引号也不成功!
孟子E章 2011-01-16
  • 打赏
  • 举报
回复
dim SqlStr="select * from [User] where 用户名= @用户名"

注意没有单引号

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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