Imports ADOX
Module module1
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 ("error code:" & err. Number. tostring & "error Description:" & 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 "generated by Windows Form DesignerCode"
Public sub new ()
Mybase. New ()
'The call is required by the Windows Form Designer.
Initializecomponent ()
'Add any initialization after initializecomponent () is called.
End sub
'Form rewriting disposal to clear the component list.
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 forms designer required
Private components as system. componentmodel. icontainer
'Note: The following procedure is required by the Windows Forms designer
'You can use the Windows Form Designer to modify this process.
'Do not use the code editor to modify it.
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 = "create Access Database"
'
'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 button#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
With me. savefiledialog1
. Addextension = true
. Defaultext = "mdb"
. Checkpathexists = true
. Filter = "(Access Database) *. mdb | *. mdb"
. Overwriteprompt = true
. Filterindex = 1
End
If me. savefiledialog1.showdialog () = dialogresult. OK then
Filename = me. savefiledialog1.filename
If filename <> "" then
Msgbox (filename)
Else
Exit sub
End if
End if
If file. exists (filename) then
Msgbox ("the file have exists! ")
File. Delete (filename)
Msgbox ("had Delete! ")
End if
Filename = filename &";"
Msgbox (filename)
If createaccessdb (filename) then
Msgbox ("sucess! ")
Else
Msgbox ("failed! ")
End if
End sub
End Class