Foxtable(狐表)用户栏目专家坐堂 → [求助]放到命令窗口报错,哪句类型转换出错?


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

主题:[求助]放到命令窗口报错,哪句类型转换出错?

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


加好友 发短信
等级:幼狐 帖子:134 积分:1047 威望:0 精华:0 注册:2014/11/24 11:07:00
[求助]放到命令窗口报错,哪句类型转换出错?  发帖心情 Post By:2015/5/28 11:33:00 [只看该作者]

'注意:本复制过程不能取取表达式列,当然不能复制表达式列
'查询各列再新建
'1.1建来源表建立参数空间
Dim DataTabSelf As DataTable = DataTables("表A")
    If DataTables.Contains("Data_" & DataTabSelf.Name) = True Then '如果表已经加载
        Return Nothing '则退出函数
    End If

'1.2为取来源表建立第二批空间
 
    Dim SumRow As Integer = DataTabSelf.DataRows.Count
    Dim SumCol As Integer = DataTabSelf.DataCols.Count
    Dim TotalCell As Integer = DataTabSelf.DataRows.Count*DataTabSelf.DataCols.Count
    Dim BaseTabName As String = "Data_" & DataTabSelf.Name
    Dim RowEmpty As Integer
    RowEmpty = 4
    Dim RowCap(RowEmpty)  As String      
    If TotalCell > 5240  Then '如果数据过多,接近5250个上限
        MessageBox.Show("数据过多,接近5250个上限,退出")
    Return Nothing '则退出函数
    End If
'1.3为目标表建立空间并复制表列,仅复制结构,不复制数据
    Dim Builder As New ADOXBuilder
    Dim tbl As ADOXTable
    Dim i As Integer = 0
    Dim j As Integer = 0
    Dim LeiXing As Integer
    Dim DcName As String
    Dim DcCaption As String
    Dim DcDatatype As Integer
    Dim DcMaxlength As String

    Builder.Open()
    tbl = Builder.NewTable( "Data_" & DataTabSelf.Name)
    With tbl
          .AddColumn( "RowColLable" ,ADOXType.String ,16)
          .AddColumn( "RowColContent" ,ADOXType.String ,200)
            For Each dc As DataCol In DataTabSelf.DataCols
               DcName = dc.Name
               DcCaption =dc.Caption
               DcDatatype =dc.Datatype.tostring()
               DcMaxlength =dc.MaxLength
             .AddColumn( DcName ,DcDatatype ,DcMaxlength)
            Next
    End With
   
    Builder.AddTable(tbl) '增加表
    Builder.Close()

    If DataTables.Contains("Data_" & DataTabSelf.Name) = False Then '如果新表没有加载
        DataTables.Load("Data_" & DataTabSelf.Name) '加载新表
    End If


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/5/28 11:44:00 [只看该作者]

Dim DataTabSelf As DataTable = DataTables("表A")
If DataTables.Contains("Data_" & DataTabSelf.Name) = True Then '如果表已经加载
    Return Nothing '则退出函数
End If

'1.2为取来源表建立第二批空间

Dim SumRow As Integer = DataTabSelf.DataRows.Count
Dim SumCol As Integer = DataTabSelf.DataCols.Count
Dim TotalCell As Integer = DataTabSelf.DataRows.Count*DataTabSelf.DataCols.Count
Dim BaseTabName As String = "Data_" & DataTabSelf.Name
Dim RowEmpty As Integer
RowEmpty = 4
Dim RowCap(RowEmpty)  As String
If TotalCell > 5240  Then '如果数据过多,接近5250个上限
    MessageBox.Show("数据过多,接近5250个上限,退出")
    Return Nothing '则退出函数
End If
'1.3为目标表建立空间并复制表列,仅复制结构,不复制数据
Dim Builder As New ADOXBuilder
Dim tbl As ADOXTable
Dim i As Integer = 0
Dim j As Integer = 0
Dim LeiXing As Integer
Dim DcName As String
Dim DcCaption As String
Dim DcDatatype As Object
Dim DcMaxlength As String

Builder.Open()
tbl = Builder.NewTable( "Data_" & DataTabSelf.Name)
With tbl
    .AddColumn( "RowColLable" ,ADOXType.String ,16)
    .AddColumn( "RowColContent" ,ADOXType.String ,200)
    For Each dc As DataCol In DataTabSelf.DataCols
        DcName = dc.Name
        DcCaption =dc.Caption
        If dc.IsBoolean Then
            DcDatatype = ADOXType. Boolean
        ElseIf dc.IsDate Then
            DcDatatype = ADOXType. DateTime
        ElseIf dc.IsNumeric Then
            If dc.datatype.Name = "Double" Then
                DcDatatype = ADOXType.Double
            ElseIf dc.datatype.Name = "Decimal"
                DcDatatype = ADOXType.Decimal
            End If
        ElseIf dc.IsString Then
            DcDatatype = ADOXType.String
        End If
        DcMaxlength =dc.MaxLength
        .AddColumn( DcName ,DcDatatype ,DcMaxlength)
    Next
End With

Builder.AddTable(tbl) '增加表
Builder.Close()

If DataTables.Contains("Data_" & DataTabSelf.Name) = False Then '如果新表没有加载
    DataTables.Load("Data_" & DataTabSelf.Name) '加载新表
End If

 


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/5/28 11:45:00 [只看该作者]

dc.datatype 不能直接转换成 ADOXType

 

所以,还需必须分别判断为好。


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


加好友 发短信
等级:幼狐 帖子:134 积分:1047 威望:0 精华:0 注册:2014/11/24 11:07:00
[分享]太谢谢了!  发帖心情 Post By:2015/5/28 12:57:00 [只看该作者]

百思未能跳出深坑,高人伸手才得救。。。。

再次谢谢!


 回到顶部