以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- 关于填充 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=108692)
|
-- 作者:实话实说
-- 发布时间:2017/10/27 13:41:00
-- 关于填充
- ExcludeExistValue
逻辑型,设为True,排除接收表中已经存在的内容。
- ExcludeNullValue
逻辑型,设为True,排除空白值。
接收表中已经存在的内容和空白值具体指的是? 另外,下面代码中,订单表和统计表都有20个字段,有18个字段匹配,另2个字段不匹配,我不想在代码中把字段一一列出,还有何方法填充
dim f As New
Filler f.SourceTable =
DataTables("订单") \'指定数据来源 f.SourceCols = "产品,客户" \'指定数据来源列 f.DataTable = DataTables("统计") \'指定数据接收表 f.DataCols =
"产品,客户" \'指定数据接收列 f.Fill()
\'填充数据
|
-- 作者:有点甜
-- 发布时间:2017/10/27 14:20:00
--
ExcludeExistValue 设置成true,可以排除重复值。
For Each dr1 As DataRow In DataTables("表A").Select("") Dim dr2 As DataRow = DataTables("表B").AddNew() For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) Then dr2(dc.Name) = dr1(dc.name) End If Next Next
|
-- 作者:实话实说
-- 发布时间:2017/10/27 15:02:00
--
同时还有2个不匹配的字段也要填充,比如表A的分类1和产品1,填充到表B的分类2和产品2
|
-- 作者:有点甜
-- 发布时间:2017/10/27 15:22:00
--
Dim ary1() As String = {"产品1", "产品2"} Dim ary2() As String = {"分类1", "分类2"} For Each dr1 As DataRow In DataTables("表A").Select("") Dim dr2 As DataRow = DataTables("表B").AddNew() For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) Then dr2(dc.Name) = dr1(dc.name) End If Next For i As Integer = 0 To ary1.length-1 dr2(ary2(i)) = dr1(ary1(i)) next Next
|
-- 作者:实话实说
-- 发布时间:2017/10/27 15:35:00
--
此主题相关图片如下:snap1.jpg
|
-- 作者:有点甜
-- 发布时间:2017/10/27 16:07:00
--
Dim ary1() As String = {"分类1", "产品1"} Dim ary2() As String = {"分类2", "产品2"} For Each dr1 As DataRow In DataTables("表A").Select("") Dim dr2 As DataRow = DataTables("表B").AddNew() For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) Then dr2(dc.Name) = dr1(dc.name) End If Next For i As Integer = 0 To ary1.length-1 dr2(ary2(i)) = dr1(ary1(i)) next Next
[此贴子已经被作者于2017/10/27 16:07:18编辑过]
|
-- 作者:实话实说
-- 发布时间:2017/10/27 16:28:00
--
如何排除重复行?
|
-- 作者:有点甜
-- 发布时间:2017/10/27 17:24:00
--
Dim ary1() As String = {"分类1", "产品1"} Dim ary2() As String = {"分类2", "产品2"}
For Each dr1 As DataRow In DataTables("表A").Select("") Dim filter As String = "1=1" For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) Then If dr1.IsNull(dc.name) Then filter &= " and " & dc.name & " is null" Else filter &= " and " & dc.name & " = \'" & dr1(dc.name) & "\'" End If End If Next For i As Integer = 0 To ary1.length-1 If dr1.IsNull(ary1(i)) Then filter &= " and " & ary2(i) & " is null" Else filter &= " and " & ary2(i) & " = \'" & dr1(ary1(i)) & "\'" End If Next Dim dr2 As DataRow = DataTables("表B").find(filter) If dr2 Is Nothing Then dr2 = DataTables("表B").addnew For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) Then dr2(dc.Name) = dr1(dc.name) End If Next For i As Integer = 0 To ary1.length-1 dr2(ary2(i)) = dr1(ary1(i)) Next end if Next
|
-- 作者:实话实说
-- 发布时间:2017/10/27 18:17:00
--
谢谢。还有1个问题,在表A和表B中都有1个相同的字段【型号规格】,我不想表A的这个字段填充到表B,尽管是匹配字段(其它匹配字段可以)
|
-- 作者:有点蓝
-- 发布时间:2017/10/27 20:04:00
--
For Each dc As DataCol In DataTables("表A").DataCols If DataTables("表B").DataCols.Contains(dc.name) andalso dc.name <> "型号规格" Then dr2(dc.Name) = dr1(dc.name) End If Next
|