Dim tb As Table = Tables(e.Form.Name & "_Table1")
tb.Fill("sele ct * fr om {物料表} where ( 单位 Is null Or 默认仓库名称 Is null )", "ksg", False)
tb.SetColVisibleWidth("代码|154|名称|204|规格型号|135|单位|36|备注|262|类别|130|类型|59|默认仓库名称|98")
For Each r As Row In tb.Rows
Dim cmd As new SQLCommand
cmd.C
cmd.CommandText = "select * fr om {t_ICItemCore} where FNumber = '" & r("代码") & "'"
Dim dt As DataTable = cmd.ExecuteReader
If dt.DataRows.Count > 0 Then
Dim dr As DataRow = dt.DataRows(0)
cmd.CommandText = "select * fr om {t_ICItemBase} where FItemID = '" & dr("FItemID") & "'"
Dim dt1 As DataTable = cmd.Ex ecuteReader
Dim dr1 As DataRow = dt1.DataRows(0)
If dr1("FDefaultLoc") <> "0" Then
cmd.CommandText = "select * fr om {t_Stock} where FItemID = '" & dr1("FDefaultLoc") & "'"
Dim dt2 As DataTable = cmd.ExecuteReader
Dim dr2 As DataRow = dt2.DataRows(0)
R("默认仓库名称") = dr2("FName")
End If
cmd.CommandText = "select * fr om {t_MeasureUnit} where FItemID = '" & dr1("FUnitID") & "'"
Dim dt3 As DataTable = cmd.ExecuteReader
Dim dr3 As DataRow = dt3.DataRows(0)
R("单位") = dr3("FName")
cmd.CommandText = "select * fro m {t_ICItemMaterial} where FItemID = '" & dr("FItemID") & "'"
Dim dt4 As DataTable = cmd.ExecuteReader
Dim dr4 As DataRow = dt4.DataRows(0)
R("备注") = dr4("Fnote")
Else
R("单位") = "无用"
R("默认仓库名称") = "无用"
End If
Next
tb.DataTable.Save
MessageBox.Show("物料更新完成")
以上代码 能不能用SQL语句直接查找出来。
[此贴子已经被作者于2018/7/3 20:38:59编辑过]