|
Dim CatalogX As New ADOX.Catalog
Dim ConnX As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub cmdOK_Click()
If txtDBName.Text = "" Then
MsgBox "请输入要生成的数据库名.", vbInformation
txtDBName.SetFocus
Exit Sub
End If
If Dir(txtDBName.Text) <> "" Then
MsgBox "要生成的数据库名已存在.", vbInformation
txtDBName.SetFocus
Exit Sub
End If
Dim ConnString As String
ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;"
ConnString = ConnString & "Data Source=" & txtDBName.Text
On Error GoTo CreateErr
'创建数据库
CatalogX.Create ConnString
CatalogX.ActiveConnection = ConnString
'建立新表格
Dim TableX As New Table
TableX.Name = "MyTable"
'向表格中添加字段并指定字段类型
TableX.Columns.Append "ID", adInteger
TableX.Columns.Append "Name", adVarWChar, 8
TableX.Columns.Append "Address", adVarWChar, 50
'向数据库中添加表格
CatalogX.Tables.Append TableX
Exit Sub
CreateErr:
MsgBox "创建数据库时发生错误:" & Err.Description, vbInformation
End Sub |
|