哪里错了??

suixaing 2012-04-12 09:35:49
Dim sqlstr As String = "select fid from file3 where tname= '" + Label1.Text + "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(sqlstr, myconn)
Dim s As String = cmd.ExecuteScalar()
label3.text = s
Dim sqlstr1 As String = "select count(*) from [file] where filename like '%s%' and fid ='s'"

如果s换成具体中文字符就可以查询,否则显示为0,为什么??
...全文
157 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
suixaing 2012-04-12
  • 打赏
  • 举报
回复
哎呀呀呀呀。。。。哪里错了呀。。。。
suixaing 2012-04-12
  • 打赏
  • 举报
回复
s 是字符串 。。
暖枫无敌 2012-04-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 3 楼 的回复:

Dim sqlstr As String = "select fid from file3 where tname= '" + Label1.Text + "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(sqlstr, myconn)
Dim dr As SqlDataReader
dr = cmd.Execu……
[/Quote]
你那个fid是什么类型?是数值型的话,去掉s两端的 ''单引号试试
suixaing 2012-04-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

Dim sqlstr As String = "select fid from file3 where tname= '" + Label1.Text + "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(sqlstr, myconn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader……
[/Quote]


报错 列名 's' 无效。
EnForGrass 2012-04-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

Dim sqlstr As String = "select fid from file3 where tname= '" + Label1.Text + "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(sqlstr, myconn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader……
[/Quote]
忘了VB了,连接符用&
Dim sqlstr1 As String = "select count(*) from [file] where filename like '%s%' and fid ='"&s&"'"
suixaing 2012-04-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

Dim sqlstr1 As String = "select count(*) from [file] where filename like '%s%' and fid ='"+s+"'"
这样不行嘛?
[/Quote]

不行 还是0.。。
EnForGrass 2012-04-12
  • 打赏
  • 举报
回复
Dim sqlstr1 As String = "select count(*) from [file] where filename like '%s%' and fid ='"+s+"'"
这样不行嘛?
暖枫无敌 2012-04-12
  • 打赏
  • 举报
回复
Dim sqlstr As String = "select fid from file3 where tname= '" + Label1.Text + "'"
Dim cmd As SqlCommand
cmd = New SqlCommand(sqlstr, myconn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
Dim s As String = dr["fid"]
label3.text = s
Dim sqlstr1 As String = "select count(*) from [file] where filename like '%'&s&'%' and fid ='&'s&'"
suixaing 2012-04-12
  • 打赏
  • 举报
回复
不是啊~我如果把s换成s代表的中文,就可以执行了。。但s是可变的,所以不可能固定在一个意思上。。
Mirror然 2012-04-12
  • 打赏
  • 举报
回复
select count(*) from [file] where filename like '%s%' and fid ='s'"

-------------
根据你的数据 来查询 改成中文可以查询 比如like '%你好%'?
那意思就是你库你有含有中文的数据
改成S不能查询 那表示你的filename列里面 没含有S的数据

62,268

社区成员

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

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

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

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