以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 代码运算太慢  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=158275)

--  作者:sanny
--  发布时间:2020/11/13 21:54:00
--  [求助] 代码运算太慢
老师, 以下代码运算太慢了,有更好的吗 ?


    Dim cmd1 As new SQLCommand
    cmd1.C

    Dim cmd4 As new SQLCommand
    cmd4.C

    Dim cmd5 As new SQLCommand
    cmd5.C

For Each rrr As Row In Tables("物料需求")


    cmd1.CommandText = "Se lect FItemID From {t_ICItemCore} Where FNumber = \'"& rrr("PartNo") & "\'"
    Dim Values = cmd1.ExecuteValues
    If Values.Count > 0 Then
        rrr("FItemID") = Values("FItemID")
        
    End If



    cmd4.CommandText = "Sel ect FPrice,FCyID,FTax From {t_SupplyEntry} Where FItemID = \'" & rrr("FItemID") & "\'and FUsed = 1 and FPrioritized = 1"
    Dim Values4 = cmd4.ExecuteValues
    If Values4.Count > 0 Then
        rrr("UnitPrice_WithoutVAT") = Values4("FPrice")
        rrr("FCyID") = Values4("FCyID")
       rrr("FVAT") = Values4("FTax")
     \' rrr("FSupID") = Values4("FSupID")

    End If

    cmd5.CommandText = "Sel ect FName From {t_Currency} Where FCurrencyID = \'" & rrr("FCyID") & "\'"
    Dim Values5 = cmd5.ExecuteValues
    If Values5.Count > 0 Then
       rrr("Currency") = Values5("FName")
    End If


If rrr("Currency") ="人民币"
rrr("ExchangeRate") = 1
ElseIf rrr("Currency") ="欧元"
rrr("ExchangeRate") = 7.7
ElseIf rrr("Currency") ="瑞士法郎"
rrr("ExchangeRate") = 7
ElseIf rrr("Currency") ="美元"
rrr("ExchangeRate") = 6.7
End If


Next

msgbox("Done !!!")

--  作者:有点蓝
--  发布时间:2020/11/14 8:50:00
--  
直接sql更新,如

dim sql as string = "update a set a.FItemID = (select top 1 FItemID from {t_ICItemCore} Where FNumber = a.PartNo), a.Currency = (Select top 1  FName From {t_Currency} Where FCurrencyID = a.FCyID) from 物料需求 a "
if Tables("物料需求").filter > "" then
sql = sql & " where " & Tables("物料需求").filter
end if

--  作者:sanny
--  发布时间:2020/11/14 13:37:00
--  
老师,这个不对,我要把Sql 表中的填入 foxtable 的表 物料需求 中。
--  作者:有点蓝
--  发布时间:2020/11/14 14:20:00
--  
物料需求如果是外部表,直接上面的sql即可。

如果是内部表或者临时表,可以考虑把需要查询的数据一次性加载出来使用,比如

cmd1.CommandText = "Se lect FItemID,FNumber From {t_ICItemCore} Where FNumber in (\'"& dataTables("物料需求")GetComboListString("PartNo").replace("|","\',\'") & "\')"
    Dim dt as datatable= cmd1.ExecuteReader
For Each rrr As Row In Tables("物料需求")
dim dr as datarow = dt.find("FNumber = \'"& rrr("PartNo") & "\'")
rrr("FItemID") = dr ("FItemID")
……