以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  查询条件可用变量替换吗?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=18228)

--  作者:fuguo
--  发布时间:2012/4/6 19:24:00
--  查询条件可用变量替换吗?

查询条件可用变量替换吗?

用SQL查询中,对查询条件可以用变量替换吗?怎么实现,有例子吗


--  作者:sloyy
--  发布时间:2012/4/6 19:34:00
--  

就是有了变量,sql语句才如此多姿多彩。

例子: 加载今天的订单数据:

Dim dt As DataTable = DataTables("订单")
If dt.SourceType = 1 Then \'Access数据源
    dt.LoadFilter = "日期 = #" & Date.Today & "#"
ElseIf dt.SourceType = 2 Then \'SQL Server数据源
    dt.LoadFilter = "日期 = \'" & Date.Today & "\'"
End If
dt.Load()