改成这样计算
For Each drwl As DataRow In DataTables("bom物料合并").DataRows
Dim q As new SQLCommand
q.ConnectionName = "k3"
q.CommandText = "Select TOP 3 FItemID,FPriceDiscount FROM {ICPurchaseEntry} LEFT JOIN {ICPurchase} ON {ICPurchaseEntry}.FInterID = {ICPurchase}.FInterID WHERE FDate <= '" & dtjs1 & "' And FPriceDiscount > 0 And FItemID = " & drwl("物料内码") & " ORDER BY {ICPurchaseEntry}.FInterID DESC"
Dim dt = q.ExecuteReader
If dt.dataRows.Count > 0 Then
drwl("均价1") = dt.Compute("Avg(FPriceDiscount)")
End If
Next