以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]请求简化代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=16410)

--  作者:dqlgood
--  发布时间:2012/2/13 14:24:00
--  [求助]请求简化代码
 

在“表A"“第一列”无重复行的情况下想要将“表A”“第二列”的项目分离到“表B”编码如下,但当项目较多时编码太长,不知如何设定变量n,请把编码简化一下。

Select Case e.DataCol.name

    Case "第二列"

        If e.DataRow.IsNull("第二列") Then

        Else

            Dim dts As List(Of DataRow)

            dts = DataTables("表B").Select("[第一列] = \'" & e.DataRow("第一列") & "\'")

            For Each dt As DataRow In dts

                dt.Delete()

            Next

            Dim p() As String = e.DataRow("第二列").split("|")

            Dim dr1 As Row = Tables("表B").AddNew()

            dr1("第二列") = p(0)

            dr1("第一列") = e.DataRow("第一列")

            If p.length > 1 Then

                Dim dr2 As Row = Tables("表B").AddNew()

                dr2("第二列") = p(1)

                dr2("第一列") = e.DataRow("第一列")

                If p.length > 2 Then

                    Dim dr3 As Row = Tables("表B").AddNew()

                    dr3("第二列") = p(2)

                    dr3("第一列") = e.DataRow("第一列")

                    If p.length > 3 Then

                        Dim dr4 As Row = Tables("表B").AddNew()

                        dr4("第二列") = p(3)

                        dr4("第一列") = e.DataRow("第一列")

 

                      ……n个

 

                    End If

                End If

            End If

        End If

End Select

[此贴子已经被作者于2012-2-13 14:24:41编辑过]

--  作者:狐狸爸爸
--  发布时间:2012/2/13 14:38:00
--  
Select Case e.DataCol.name
    Case "第二列"
        If e.DataRow.IsNull("第二列") = False Then
            Dim dts As List(Of DataRow)
            dts = DataTables("表B").Select("[第一列] = \'" & e.DataRow("第一列") & "\'")
            For Each dt As DataRow In dts
                dt.Delete()
            Next
            Dim p() As String = e.DataRow("第二列").split("|")
            For i As Integer = 0 To p.Length - 1
                Dim dr1 As Row = Tables("表B").AddNew()
                dr1("第二列") = p(i)
                dr1("第一列") = e.DataRow("第一列")
            Next
        End If
End Select