在表中不能完成.下例用的ADOX实现的,也可以采用SQL
Columns 和 Tables 的 Append 方法、Name 属性范例 (VB)
下面的代码演示如何创建新的表。' BeginCreateTableVB
Sub Main()
On Error GoTo CreateTableError
Dim tbl As New Table
Dim cat As New ADOX.Catalog
' Open the Catalog.
cat.ActiveConnection = "rovider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb';"
tbl.Name = "MyTable"
tbl.Columns.Append "Column1", adInteger
tbl.Columns.Append "Column2", adInteger
tbl.Columns.Append "Column3", adVarWChar, 50
cat.Tables.Append tbl
Debug.Print "Table 'MyTable' is added."
'Delete the table as this is a demonstration.
cat.Tables.Delete tbl.Name
Debug.Print "Table 'MyTable' is deleted."
'Clean up
Set cat.ActiveConnection = Nothing
Set cat = Nothing
Set tbl = Nothing
Exit Sub
CreateTableError:
Set cat = Nothing
Set tbl = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndCreateTableVB
[此贴子已经被作者于2006-4-22 18:58:02编辑过]
|