Public Function CreateAccessDB(ByVal NewDBPathName As String) As Integer
Dim i As Integer = 1
Dim cat As Catalog = New Catalog()
Try
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & NewDBPathName & _
"Jet OLEDB:Engine Type=5")
'Console.WriteLine("Database Created Successfully")
Catch
i = 0
MsgBox("錯誤號碼 : " & Err.Number.ToString & " 錯誤描述:" & Err.Description.ToString)
End Try
cat = Nothing
Return i
End Function
End Module
Imports System.IO
Imports ADOX
Public Class Form1
Inherits System.Windows.Forms.Form
Dim filename As String = ""
#Region " Windows 表單設計器產生的程式碼 "
Public Sub New()
MyBase.New()
'該調用是 Windows 表單設計器所必需的。
InitializeComponent()
'在 InitializeComponent() 調用之後添加任何初始化
End Sub
'表單重寫處置以清理組件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 表單設計器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下過程是 Windows 表單設計器所必需的
'可以使用 Windows 表單設計器修改此過程。
'不要使用代碼編輯器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents SaveFileDialog2 As System.Windows.Forms.SaveFileDialog
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button()
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
Me.SaveFileDialog2 = New System.Windows.Forms.SaveFileDialog()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(160, 104)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(232, 48)
Me.Button1.TabIndex = 0
Me.Button1.Text = "建立access資料庫"
'
'SaveFileDialog1
'
Me.SaveFileDialog1.FileName = "doc1"
'
'SaveFileDialog2
'
Me.SaveFileDialog2.FileName = "doc1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(160, 192)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(224, 56)
Me.Button2.TabIndex = 1
Me.Button2.Text = "build dataase"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(592, 286)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str1 As String = "d:\mrfu\newaccess"
Dim str2 As String = "newAccess"
If File.Exists("d:\mrfu\newmdb.mdb") Then
MsgBox("the file have exists !")
Exit Sub
End If
If CreateAccessDB(str1) Then
MsgBox("sucess!")
Else
MsgBox("failed!")
End If
'me.SaveFileDialog1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click