以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  逻辑列自动复制行问题,请教老师们  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=25855)

--  作者:mamuaiqing
--  发布时间:2012/11/18 22:44:00
--  逻辑列自动复制行问题,请教老师们

看了帮助文件中的逻辑列“自动复制行”,有点疑惑,如果接收数据的是2张表呢?代码该怎么写比较简洁?以下是帮助文件中的代码,请教老师们

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
    Dim nma() As String = {"A1","A2","A3","A4"}
\'A表数据来源列

   
Dim nmb() As String = {"B1","B2","B3","B4"} \'B表数据接收列
   
Dim dr As DataRow = DataTables("表B").AddNew
   
For i As Integer = 0 To nma.Length - 1
        dr(nmb(i)) = e.DataRow(nma(i))
   
Next
End
If


--  作者:kevin
--  发布时间:2012/11/19 9:07:00
--  
If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then Dim nma() As String = {"A1","A2","A3","A4"} \'A表数据来源列 Dim nmb() As String = {"B1","B2","B3","B4"} \'B表数据接收列 Dim nmc() As String = {"B1","B2","B3","B4"} \'B表数据接收列 Dim dr As DataRow = DataTables("表B").AddNew Dim cr As DataRow = DataTables("表C").AddNew For i As Integer = 0 To nma.Length - 1 dr(nmb(i)) = e.DataRow(nma(i)) cr(nmc(i)) = e.DataRow(nma(i)) Next End If 这样试试
--  作者:狐狸爸爸
--  发布时间:2012/11/19 9:08:00
--  

一样:

 

 

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
    Dim nma() As String = {"A1","A2","A3","A4"} \'A表数据来源列
    Dim nmb() As String = {"B1","B2","B3","B4"} \'B表和C表数据接收列
    Dim dr1 As DataRow = DataTables("表B").AddNew
    Dim dr2 As DataRow = DataTables("表C").AddNew
    For i As Integer = 0 To nma.Length - 1
        dr1(nmb(i)) = e.DataRow(nma(i))
        dr2(nmb(i)) = e.DataRow(nma(i))
    Next
End If


--  作者:mamuaiqing
--  发布时间:2012/11/19 19:26:00
--  

感谢老爹跟Kevin的帮助,尝试了下表C接收的列设置2列时出现错误,代码为:

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
    Dim nma() As String = {"A1","A2","A3","A4"} \'A表数据来源列
    Dim nmb() As String = {"B1","B2","B3","B4"} \'B表数据接收列
    Dim nmc() As String = {"B1","B2"} \'C表数据接收列
    Dim dr As DataRow = DataTables("表B").AddNew
    Dim cr As DataRow = DataTables("表C").AddNew
    For i As Integer = 0 To nma.Length - 1
        dr(nmb(i)) = e.DataRow(nma(i))
        cr(nmc(i)) = e.DataRow(nma(i))
    Next
End If

 

再请教个问题,自动复制行中三表的列数是不是需要一样?


--  作者:狐狸爸爸
--  发布时间:2012/11/19 20:43:00
--  

如果长度不一致,要分开写才行:

 

 

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
    Dim nma() As String = {"A1","A2","A3","A4"} \'A表数据来源列
    Dim nmb() As String = {"B1","B2","B3","B4"} \'B表数据接收列
    Dim nmc() As String = {"B1","B2"} \'C表数据接收列
    Dim dr As DataRow = DataTables("表B").AddNew
    Dim cr As DataRow = DataTables("表C").AddNew
    For i As Integer = 0 To nmb.Length - 1
        dr(nmb(i)) = e.DataRow(nma(i))
    Next
    For i As Integer = 0 To nmc.Length - 1
        cr(nmc(i)) = e.DataRow(nma(i))
    Next
End If


--  作者:mamuaiqing
--  发布时间:2012/11/20 0:57:00
--  

图片点击可在新窗口打开查看终于弄明白了,感谢老爹