以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]放到命令窗口报错,哪句类型转换出错?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=68966)

--  作者:whyfoxtable
--  发布时间: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


--  作者:大红袍
--  发布时间: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

 


--  作者:大红袍
--  发布时间:2015/5/28 11:45:00
--  

dc.datatype 不能直接转换成 ADOXType

 

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


--  作者:whyfoxtable
--  发布时间:2015/5/28 12:57:00
--  [分享]太谢谢了!

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

再次谢谢!