Foxtable(狐表)用户栏目专家坐堂 → 遍历数组得到的col如何正确赋值到代码中……


  共有6381人关注过本帖树形打印复制链接

主题:遍历数组得到的col如何正确赋值到代码中……

帅哥哟,离线,有人找我吗?
cnsjroom
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
遍历数组得到的col如何正确赋值到代码中……  发帖心情 Post By:2022/9/9 2:20:00 [显示全部帖子]

遍历数组得到的Col 如何正确赋值到代码中……

 

当前代码如下:

Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.Con nec tio nN ame = "主数据源"
cmd.CommandText = "Sel ect * From sys_Navigation"
dt = cmd.ExecuteReader()

Dim cols As String() = {"第1节","第2节","第3节","第4节","第5节"}   是列名数组
For Each Col As String In cols

    Dim Products As List(Of String())
    Products = DataTables("文书窗体导航表").GetValues(Col)   '从文书窗体导航表中分别按col数组依次读取不重复值,并进行数据查找后,更新对应的值
    For Each Product As String() In Products
        Dim Products1 As List(Of String())
        Products1 = dt.sqlGetValues("ID|Name|formid","ID ='" & Product(0) & "'")
        For Each Product1 As String() In Products1
            Dim dr As DataRow = DataTables("文书窗体导航表").find("'"& Col & "' = '" & Product(0) &"'")
            If dr IsNot Nothing Then
                dr(Col & "名称") = Product1(1)
                dr("窗体id") = Product1(2)
                dr("导航名") = Product1(1)
            End If
            'Dim drs As List(of DataRow)
            'drs = DataTables("文书窗体导航表").Select("'"& Col & "' = '" & Product(0) &"'")
            'For Each dr As DataRow In drs
            'If dr IsNot Nothing Then
            'dr(name & "名称") = Product1(1)
            'dr("窗体id") = Product1(2)
            'dr("导航名") = Product1(1)
            'End If
            'Next
        Next
    Next
Next

 

 

代码运行提示错误:

错误的事件名称自定义函数,文书窗体生成数据更新简约
System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.InvalidCastException: 无法将类型为“System.Collections.Generic.List`1[System.String]”的对象强制转换为类型“System.Collections.Generic.List`1[System.String[]]”。
   在 UserCode.AeTeE22NuDkXILf2A(Object[] Args)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   在 Foxtable.UserFunctions.Execute(String Name, Object[] Args)
2022-09-09 03:56:35

[此贴子已经被作者于2022/9/9 3:56:04编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
cnsjroom
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)列名不需要引号Dim dr As DataRow = ...  发帖心情 Post By:2022/9/9 8:58:00 [显示全部帖子]

Products = DataTables("文书窗体导航表").GetValues(Col)  

老师这个地方运行也会报一楼错误!麻烦老师指导下  在这地方col要怎么写呢?

 


 回到顶部
帅哥哟,离线,有人找我吗?
cnsjroom
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)3楼代码没有问题。检查其它代码  发帖心情 Post By:2022/9/9 9:23:00 [显示全部帖子]

老师  经再次检测  其他代码正常   但是下面这句就不正常了

Products = DataTables("文书窗体导航表").GetValues(Col)   注释掉就不会报错   不注释掉就如图错误


图片点击可在新窗口打开查看此主题相关图片如下:333.png
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
cnsjroom
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)Dim Products As List(Of String())改...  发帖心情 Post By:2022/9/9 15:54:00 [显示全部帖子]

谢谢老师,在老师指导下完美运行!

当前代码如下:

Functions.Execute("文书窗体生成")
Dim cmd As New SQLCommand
Dim dt As DataTable
cmd.Conn ecti on Name = "主数据源"
cmd.CommandText = "Sel ect * From sys_Navigation"
dt = cmd.ExecuteReader()

Dim cols As String() = {"第1节","第2节","第3节","第4节","第5节"}
For Each Col As String In cols
    output.show(Col)
    Dim Products As List(Of String)
    Products = DataTables("文书窗体导航表").GetValues(Col)
    For Each Product As String In Products
        Dim Products1 As List(Of String())
        Products1 = dt.sqlGetValues("ID|Name|formid","ID ='" & Product & "'")
        For Each Product1 As String() In Products1
            'Dim dr As DataRow = DataTables("文书窗体导航表").find(Col & " = '" & Product &"'")
            'If dr IsNot Nothing Then
            'dr(Col & "名称") = Product1(1)
            'dr("窗体id") = Product1(2)
            'dr("导航名") = Product1(1)
            'End If
            Dim drs As List(of DataRow)
            drs = DataTables("文书窗体导航表").Se le ct(Col & " = '" & Product &"'")
            For Each dr As DataRow In drs
                If dr IsNot Nothing Then
                    dr(Col & "名称") = Product1(1)
                    dr("窗体id") = Product1(2)
                    dr("导航名") = Product1(1)
                End If
            Next
        Next
    Next
Next
DataTables("文书窗体导航表").save


 回到顶部