怎么样才能使vb 传变量@userid = Textbox1.text

liyingzi 2008-03-17 07:37:14
Dim @userid As String
@userid = Textbox1.text

Dim conn As New SqlConnection("data source=liming;initial catalog=zls;uid=sa;pwd=;")
Dim asapter As New SqlDataAdapter("select * whereuserid=@userid order by w.id", conn)
Dim mydataset As New DataSet()
...全文
125 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
liyingzi 2008-03-18
  • 打赏
  • 举报
回复
感谢大家怎么热情
zheninchangjiang 2008-03-18
  • 打赏
  • 举报
回复
不是不能用
用 textbox1.text.replace("'","''")
HimeTale 2008-03-18
  • 打赏
  • 举报
回复

Dim daSelect As New SqlDataAdapter()
daSelect.SelectCommand = New SqlCommand()
daSelect.SelectCommand.Connection = Me.Connection
daSelect.SelectCommand.CommandText = "Select * from table1 where Keyid=@pTYPE"
daSelect.SelectCommand.Parameters.Clear()
daSelect.SelectCommand.Parameters.Add("@pTYPE", SqlDbType.VarChar).Value = Textbox1.text
'Fill
daSelect.Fill(xxxxxx)


千万别用daSelect.SelectCommand.CommandText="Select * from table1 where Keyid="+Textbox1.text 这种方法
lucky749 2008-03-18
  • 打赏
  • 举报
回复
Dim asapter As New SqlDataAdapter("select * whereuserid='"& @userid &"' order by w.id", conn)
rangeon 2008-03-18
  • 打赏
  • 举报
回复
就算你的代码不报错,这样也不对啊
Dim asapter As New SqlDataAdapter("select * whereuserid=@userid order by w.id", conn)
至少得这样
Dim asapter As New SqlDataAdapter("select * whereuserid=" + @userid + " order by w.id", conn)
chuxue1342 2008-03-18
  • 打赏
  • 举报
回复
Dim @userid As String
@userid = Textbox1.text
------------------------------------------
申明变量都有错!@在C#里面是一个转义符号,在VB.NET不用
还有,变量连接,vb.net中用&,也可以用+,你改一下:

Dim userid As String
userid = Textbox1.text
Dim conn As New SqlConnection("data source=liming;initial catalog=zls;uid=sa;pwd=;")
Dim asapter As New SqlDataAdapter("select * whereuserid=" & userid &" order by w.id", conn)
Dim mydataset As New DataSet()
steven_srl 2008-03-18
  • 打赏
  • 举报
回复
"select * whereuserid=@userid order by w.id"
里面是字符串,@userid怎么可能传递过去

"select * whereuserid="+ textbox1.text +"order by w.id"
字符串的连接,这样可以保证得到textbox1里的数据.最好是用textbox1.text.trim
ConanKid 2008-03-17
  • 打赏
  • 举报
回复
@useid是T-SQL的声明方法,你用在VB.NET中?你把两种语言混淆了.建议你直接用:("select * whereuserid=" textbox1.text "order by w.id", conn)
hc8112_boy 2008-03-17
  • 打赏
  • 举报
回复
你用的什么,这一句不报错??
Dim @userid As String


---------------
dim userid as string
userid=textbox1.text

然后找一下sqlcommand.parameters.Add的资料
liyingzi 2008-03-17
  • 打赏
  • 举报
回复
"+Textbox1.text+"

16,717

社区成员

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

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