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


  共有6379人关注过本帖平板打印复制链接

主题:遍历数组得到的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编辑过]

 回到顶部