以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  跨表取值(已解决)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=31692)

--  作者:caiyt0
--  发布时间:2013/4/19 8:19:00
--  跨表取值(已解决)
当表A[jth]=表B[jth]时,表A的[jx]=表B的[jtlx],请问代码怎写
[此贴子已经被作者于2013-4-22 15:06:59编辑过]

--  作者:Bin
--  发布时间:2013/4/19 8:38:00
--  
表A和表B是什么关联? 表A的[jth]=表B[jth]时?  等于表B的哪一行啊? 在所有行中只要找到类似的就匹配吗?
--  作者:lsy
--  发布时间:2013/4/19 8:39:00
--  
For i1 As Integer = 0 To Tables("表A").Rows.Count - 1
    For i2 As Integer = 0 To Tables("表B").Rows.Count - 1
        If Tables("表A").Rows(i1)("jth") = Tables("表B").Rows(i2)("jth") Then
            Tables("表A").Rows(i1)("jx")  = Tables("表B").Rows(i2)("jtlx")
        Else
            Continue For
        End If
    Next
Next

--  作者:lsy
--  发布时间:2013/4/19 8:53:00
--  
以下是引用muhua在2013-4-19 8:43:00的发言:
If e.DataCol.Name = "第一列"
    If e.NewValue > "" Then
        Dim dr As DataRow = DataTables("表B").Find("第一列=\'" & e.DataRow("第一列") & "\'")
        If dr Is Nothing Then
            e.DataRow("第二列") = Nothing
        Else
            e.DataRow("第二列") = dr("第二列")
        End If
    Else
        e.DataRow("第二列") = dr("第二列")
    End If   
End If
测试过find的效率,似乎很低,都不敢用了。
 


--  作者:lsy
--  发布时间:2013/4/19 9:14:00
--  

测试了三种查找最大号的方法。

第一个最快:

Dim s As String = DataTables("数据字典").Compute("Max(编号)")
DataTables("数据字典").LoadFilter = "编号 = \'" & s & "\'"
DataTables("数据字典").Load()

第二个似乎稍慢,不明显:

DataTables("数据字典").LoadOrder = "编号 Desc"
DataTables("数据字典").LoadTop = "1"
DataTables("数据字典").Load()

第三个慢的让人烦躁了:

Dim dr As DataRow = DataTables("数据字典").Find("编号 = max(编号)")
DataTables("数据字典").LoadFilter = "编号 = \'" & dr("编号") & "\'"
DataTables("数据字典").Load()

还是最后一个效率最高:
Dim ld As Long
Dim cmd As New SQLCommand
cmd.CommandText = "Select Max(编号) From {订单}"
ld = cmd.ExecuteScalar()


--  作者:lsy
--  发布时间:2013/4/19 9:20:00
--  
以下是引用muhua在2013-4-19 9:19:00的发言:

我也测试下。

数据量越大越明显。


--  作者:FoxMan
--  发布时间:2013/4/19 9:31:00
--  
以下是引用lsy在2013-4-19 9:14:00的发言:

测试了三种查找最大号的方法。

第一个最快:

Dim s As String = DataTables("数据字典").Compute("Max(编号)")
DataTables("数据字典").LoadFilter = "编号 = \'" & s & "\'"
DataTables("数据字典").Load()

第二个似乎稍慢,不明显:

DataTables("数据字典").LoadOrder = "编号 Desc"
DataTables("数据字典").LoadTop = "1"
DataTables("数据字典").Load()

第三个慢的让人烦躁了:

Dim dr As DataRow = DataTables("数据字典").Find("编号 = max(编号)")
DataTables("数据字典").LoadFilter = "编号 = \'" & dr("编号") & "\'"
DataTables("数据字典").Load()

还是最后一个效率最高:
Dim ld As Long
Dim cmd As New SQLCommand
cmd.CommandText = "Select Max(编号) From {订单}"
ld = cmd.ExecuteScalar()


嵌套MAX測試對FIND不公平吧:

應該這樣試試

Dim s As String = DataTables("数据字典").Compute("Max(编号)")

Dim dr As DataRow = DataTables("数据字典").Find("编号 = \'" &  s  & "\'")
DataTables("数据字典").LoadFilter = "
[_Identify] = " &  dr("_Identify") 

DataTables("数据字典").Load()



--  作者:lsy
--  发布时间:2013/4/19 9:41:00
--  
以下是引用FoxMan在2013-4-19 9:31:00的发言:

可以考虑。