以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  查询数据  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=107812)

--  作者:qaz
--  发布时间:2017/10/10 17:53:00
--  查询数据
想从好几个表中查询是否有某一个数据,怎么写代码简洁一些?
--  作者:有点甜
--  发布时间:2017/10/10 17:57:00
--  

Dim ts() As String = {"表A", "表B", "表C"}
For Each t As String In ts
    Dim fdr As DataRow = DataTables(t).Find("")
    If fdr IsNot Nothing Then
       
    End If
Next


--  作者:qaz
--  发布时间:2017/10/11 15:20:00
--  
这样还是得在代码中输入列名。
数据涉及的列比较多,所以想在整个表中查询,如何写代码?

--  作者:有点甜
--  发布时间:2017/10/11 15:33:00
--  
Dim ts() As String = {"表A", "表B", "表C"}
For Each t As String In ts
    Dim dt As DataTable = DataTables(t)
    For Each dc As DataCol In dt.datacols
        Dim fdr As DataRow = dt.Find("convert(" & dc.name & ",\'System.String\') = \'" & 123 & "\'")
        If fdr IsNot Nothing Then
            msgbox(3)
        End If
    Next
Next

--  作者:qaz
--  发布时间:2017/10/11 17:58:00
--  
Dim ts() As String = {"表A", "表B", "表C"}
For Each t As String In ts
    Dim dt As DataTable = DataTables(t)
    For Each dc As DataCol In dt.datacols
        Dim fdr As DataRow = dt.sqlFind("convert(" & dc.name & ",\'System.String\') = \'" & 123 & "\'")
        If fdr IsNot Nothing Then
            msgbox(3)
        End If
    Next
Next
只是将Find改成sqlFind,怎么就查找不到了?

--  作者:有点甜
--  发布时间:2017/10/11 21:14:00
--  

多表、多列,尽量不要用sqlFind,不然多次使用sqlFind,效率很慢的。

 

Dim ts() As String = {"表A", "表B", "表C"}
For Each t As String In ts
    Dim dt As DataTable = DataTables(t)
    For Each dc As DataCol In dt.datacols
        If dc.IsString Then
            Dim fdr As DataRow = dt.sqlFind(dc.name & " = \'" & 123 & "\'")
            If fdr IsNot Nothing Then
                msgbox(3)
            End If
        End If
    Next
Next


--  作者:qaz
--  发布时间:2017/10/13 10:21:00
--  
找到数据后,想要只加载找到的行(数据源为外部数据源),应该如何写代码?
--  作者:有点甜
--  发布时间:2017/10/13 10:33:00
--  
Dim ts() As String = {"表A", "表B", "表C"}
For Each t As String In ts
    Dim dt As DataTable = DataTables(t)
    Dim idxs As String = "-1,"
    For Each dc As DataCol In dt.datacols
        If dc.IsString Then
            Dim fdr As DataRow = dt.sqlFind(dc.name & " = \'" & 123 & "\'")
            If fdr IsNot Nothing Then
                idxs = idxs & fdr("_Identify") & ","
                Exit For
            End If
        End If
    Next
    dt.LoadFilter = "[_Identify] in (" & idxs.trim(",") & ")"
    dt.load
Next

--  作者:qaz
--  发布时间:2017/10/13 11:20:00
--  
好的,谢谢
--  作者:qaz
--  发布时间:2017/12/14 16:57:00
--  
sqlFind只能查找到符合的一条数据,有时候符合的数据比较多,需要在查找到后,并将符合数据加载,应该怎么写呢?