以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]从后台(外部数据源)筛选记录 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=91977) |
-- 作者:qscwdvefb -- 发布时间:2016/10/23 17:17:00 -- [求助]从后台(外部数据源)筛选记录 怎样改这段代码 Dim dr1 As DataRow = DataTables("T246").SQLFind("[F4411] Is Not Null", "F4411", 0) Dim dr2 As DataRow = DataTables("T246").SQLFind("[F4411] Is Not Null", "F4411 Desc",0) If dr1 Is Nothing OrElse dr2 Is Nothing Then Return Dim d1 As Date Dim d2 As Date Dim drl0 As DataRow Dim dt1 As Date =dr1("F4411") Dim dt2 As Date =dr2("F4411") Dim val1 As New List (of String) val1= DataTables("T246").GetValues("F4386") Dim d As Integer = dt2.Year -dt1.Year Dim j As Integer = 0 Dim drl As New List (of DataRow) For i As Integer = 0 To d d1 = New Date(dt1.Year+i-1,11,5) \'取得该年的第一天 d2 = new Date(dt1.Year+i,11,5) \'取得该年的最后一天 For Each val As String In val1 drl0 = DataTables("T246").Find("[F4411] >= #" & d1 & "# And [F4411] <= #" & d2 & "# And [F4386] =\'" & val & "\'","F4411 Desc",0) If drl0 IsNot Nothing Then drl.add(drl0) j= j+1 End If Next Next For k As Integer = 0 To j-1 If Filter > "" Then Filter = Filter & " or " End If filter = filter & "[T246Id] = \'" & drl(k)("T246Id") & "\'" Next 使它能够从外部数据源筛选出数据呢? (这段代码大概的意思是在每年的上一年11月5日到下一年的11月5日之间从这一年段的若干条记录筛选出最晚的记录,就是最接近下一年11月5日的记录) ps:F4411是日期,T246是表,F4386是用户姓名,T246ID是唯一标识每一行。 |
-- 作者:狐狸爸爸 -- 发布时间:2016/10/23 17:55:00 -- 这里用的是SQLFind: Dim dr1 As DataRow = DataTables("T246").SQLFind("[F4411] Is Not Null", "F4411", 0) 但是这里用的是Find: drl0 = DataTables("T246").Find("[F4411] >= #" & d1 & "# And [F4411] <= #" & d2 & "# And [F4386] =\'" & val & "\'","F4411 Desc",0) 这是为什么?
筛选后台数据: Dim Filter AS string = "[T246Id] in (" For each dr as datarow in drl
filter = filter & "\'" & dr("T246Id") & "\',"
next
Filter = Filtrer.Trim(",") & ")"
DataTables("T246").LoadFilter = Filter
DataTables("T246").Load IN运算符 IN运算符是用来判断一个表达式的值是否属于一个指定列表中的值。 例如同样是加载产品PD01和PD02的订单,用IN运算符可以简化为: SELECT * FR OM {订单} WHERE 产品 IN (\'PD01\',\'PD02\') 可以用NOT关键词来进行反向的操作,例如加载除产品PD01和PD02之外的订单: SELECT * FR OM {订单} WHERE 产品 NOT IN (\'PD01\',\'PD02\') 显然,指定的值越多,IN运算符的优势越明显。
注意如果是数值列,就不需要用单引号,例如:
编号 IN (1,2,3) |
-- 作者:qscwdvefb -- 发布时间:2016/10/24 14:01:00 -- 不好意思,是我疏忽了,那只要把find改为SQLFind,GetValues改为SQLGetValues就可以用这段代码从后台处理全部数据了? |