运行的代码如下,连接的是外部数据源。
Dim Builder As New ADOXBuilder("ctais2")
Dim tbl As ADOXTable
Builder.Open()
tbl = Builder.NewTable("xx") '创建表
With tbl
For Each dc As Data.DataColumn In DataTables("DJ_NSRXX").baseTable.Columns
If DataTables("DJ_NSRXX").DataCols.Contains(dc.ColumnName) = False Then
Continue For
End If
If dc.DataType Is Gettype(String)
If dc.maxlength > 0 And dc.MaxLength < 256 Then
tbl.AddColumn(dc.ColumnName, ADOXType.String, dc.maxlength)
Else
tbl.AddColumn(dc.ColumnName, ADOXType.text)
End If
ElseIf dc.datatype Is Gettype(Date) Then
tbl.AddColumn(dc.ColumnName, ADOXType.DateTime)
ElseIf dc.datatype Is Gettype(Boolean) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Boolean)
ElseIf dc.datatype Is Gettype(Integer) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Integer)
ElseIf dc.datatype Is Gettype(Long) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Long)
ElseIf dc.datatype Is Gettype(Short) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Short)
ElseIf dc.datatype Is Gettype(Byte) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Byte)
ElseIf dc.datatype Is Gettype(Double) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Double)
ElseIf dc.datatype Is Gettype(Single) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Single)
ElseIf dc.datatype Is Gettype(Decimal) Then
tbl.AddColumn(dc.ColumnName, ADOXType.Decimal)
此主题相关图片如下:未命名.jpg
End If
Next
End With
Builder.AddTable(tbl) '增加表
Builder.Close()
MessageBox.show("生成新表成功,将重新打开项目")
syscmd.project.Open(ProjectFile)