一寸法师百度云:VB查询问题 哪位大哥帮一下忙
来源:百度文库 编辑:神马品牌网 时间:2024/10/04 22:23:20
Dim strsql As String
strsql = "select * from 每日药品计量 where 日期 ='" & dtptime.Value & "'"
If txtyao.Text <> "" Then
strsql = strsql & "' and 药品代码= '" & txtyao.Text
End If
Adodc1.RecordSource = strsql
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
我的代码错了,为什么它只能实现对时间的查找,而一对药品代码查找就出错啊。郁闷啊!
加上& "'" 也还是不行啊。。为什么啊?
strsql = "select * from 每日药品计量 where 日期 ='" & dtptime.Value & "'"
If txtyao.Text <> "" Then
strsql = strsql & "' and 药品代码= '" & txtyao.Text
End If
Adodc1.RecordSource = strsql
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
我的代码错了,为什么它只能实现对时间的查找,而一对药品代码查找就出错啊。郁闷啊!
加上& "'" 也还是不行啊。。为什么啊?
If txtyao.Text <> "" Then
strsql = strsql & "' and 药品代码= '" & txtyao.Text
End If
前面多了个单引号,后面少了个单引号
sql语句少了一个引号了吧,
If txtyao.Text <> "" Then
strsql = strsql & "' and 药品代码= '" & txtyao.Text
End If
改为
If txtyao.Text <> "" Then
strsql = strsql & "' and 药品代码= '" & txtyao.Text & "'"
End If
strsql = strsql & "' and 药品代码= '" & txtyao.Text
很不幸 ... 最后少了个引号
strsql = strsql & "' and 药品代码= '" & txtyao.Text & "'"