vb中sql语句引用变量该如何写?

Lordy 2000-10-13 12:29:00
比如:dim I as integer
i=cint(text1.text)
adodc1.recordsource="select * from Table1 where field1>I"
^^^
怎么写阿?
...全文
732 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xh_zhou 2000-10-13
  • 打赏
  • 举报
回复
在vb的脚本里用法是:"select * from table1 where field>'"&i&"',不知道vb有无此用法?
你可以在vb中用querydef,它的sql可以写成:querydef1.sql="parameters i integer;select * from ......",使用时对i赋值即可,赋值方法是querydef1![i]=thenum
DimVar 2000-10-13
  • 打赏
  • 举报
回复
dim I as integer
i=cint(text1.text)
adodc1.recordsource="select * from Table1 where field1>" & i

blstar 2000-10-13
  • 打赏
  • 举报
回复
有几点补充:

1.在引用string变量时要注意其中的"'"号,不然就有麻烦。最好编个函数。如:Public Function CheckForQuote(str As String) As String
Dim i As Integer
Dim s As String
Dim xs As String

If Len(str) < 1 Then
CheckForQuote = str
Else
s = ""
For i = 1 To Len(str)
xs = Mid(str, i, 1)
s = s & IIf(xs = "'", xs & "'", xs)
Next
End If

CheckForQuote = s


End Function

使用:adodc1.RecordSource="select * from table1 where field1 like " & CheckForQuote(s1)
monday 2000-10-13
  • 打赏
  • 举报
回复
同意以上的说法:

asp(vb script):
"select * from table1 where filed1>"&i
变量可不用cstr之类的函数转换

vb
"select * from table1 where field1>"+str(i)

另,若field1是text型的,应改为
"select * from table1 where field1='"+i+"'" (asp vb script)
"select * from table1 where field1='"+str(i)+"'"

若是日期型的,分界符为“#”象
".....field1=#"+i+"#"等等
  • 打赏
  • 举报
回复

dim I as integer
i=cint(text1.text)
adodc1.recordsource="select * from Table1 where field1" & str(I)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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