数据库为sql server 2000.
数据库表中某列名为dDate,类型为DateTime.想根据textbox输入的内容进行查找如果输入:2007-12-12 则sql为 select * from table where dDate = '2007-12-12'如果输入:>=2007-12-12 则sql为 select * from table where dDate >= '2007-12-12'如果输入:<=2007-12-12 and >=2007-11-13 则sql为 select * from table where dDate<='2007-12-12' and dDate>='2007-11-13'大家有没有什么好的办法?
求源码 感谢
数据库表中某列名为dDate,类型为DateTime.想根据textbox输入的内容进行查找如果输入:2007-12-12 则sql为 select * from table where dDate = '2007-12-12'如果输入:>=2007-12-12 则sql为 select * from table where dDate >= '2007-12-12'如果输入:<=2007-12-12 and >=2007-11-13 则sql为 select * from table where dDate<='2007-12-12' and dDate>='2007-11-13'大家有没有什么好的办法?
求源码 感谢
解决方案 »
- vba中关于for嵌套循环和单循环中step值的改变!!!
- 怎样判断用户对哪些表有操作权限
- 请指出我的SQL语句错误
- 请问一下 Chr$(2),Left$("70005", 5)这些都代表什么意思啊?在线等待!
- 怎么才能得到一个EXE文件是否在运行呢?我想双击个EXE文件,开始播放声音,当我第二次双击的时候停止播放?怎么实现呢?
- 如何实现指定主题的邮件的接收?
- 代码出了问题,可以帮忙看一下吗?
- 关于 BeginUpdateResource系列函数的问题,高手请进
- 请教一下vb的一个问题
- 救急:求解“vb的ado控件在调用数据库时遇到数据库被其他用户锁定的解决办法”
- 求助:MDI窗口无法使用
- 很简单的,vb连接access,按id查询
dim tmp() as string
dim sql as string sql="select * from tb where ddate "
tmp=split(text1,"=")
if ubound(tm)=0 then
s="='"& text1 &"'"
else
s=tmp(0) & "=" &"'" & tmp(1) &"'"
end ff
sql=sql & s
然后程序中用下面方式合成:sql = "select * from table where " & replace(text1.text, "日期", "dDate")
你何不用二个textbox来输入日期?
Dim s As String
Dim tmp() As String
s = Text1
s = Replace(s, "=", "")
s = Replace(s, ">", "")
s = Replace(s, "<", "")
tmp = Split(LCase(s), "and")
If UBound(tmp) = 0 Then
s = "='" & Text1 & "'"
Else
s = Replace(Text1, Trim(tmp(0)), "'" & Trim(tmp(0)) & "'")
s = Replace(s, Trim(tmp(1)), "'" & Trim(tmp(1)) & "'")
End If
Debug.Print "select * from tb where edate " & s
Dim s As String
Dim tmp() As String
s = Text1
s = Replace(s, "=", "")
s = Replace(s, ">", "")
s = Replace(s, "<", "")
tmp = Split(LCase(s), "and")
If UBound(tmp) = 0 Then
s = "='" & Text1 & "'"
Else
s = Replace(Text1, Trim(tmp(0)), "'" & Trim(tmp(0)) & "'")
s = Replace(s, Trim(tmp(1)), "'" & Trim(tmp(1)) & "'")
s = Replace(s, "and", "and ddate")
End If
Debug.Print "select * from tb where ddate " & s