How to create access database with vb.net program!

  • Thread starter Thread starter yonggangwang
  • Start date Start date
Y

yonggangwang

Hello:
I use system.io.filestream to create example.mdb, but the file size is
0, access 2000 can not recognize it.How to create access database with
vb.net automatically!

thanks a lot!!!
 
U¿ytkownik "yonggangwang said:
Hello:
I use system.io.filestream to create example.mdb, but the file size is
0, access 2000 can not recognize it.How to create access database with
vb.net automatically!

You can use ADOX (and late binding), for example:

Public Function CreateDb(ByVal path As String)
Dim adox As Object
adox = CreateObject("ADOX.Catalog")
adox.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=" + path + _
"Jet OLEDB:Engine Type=5;")
End Function

Regards,
Grzegorz
 
Than you very much!!!
This is my first time for use this news group.
My english is very bad, I am very exciting
for you reply , so fast , than you again,
have a good holly en!!
 
I try it, but it's not work.
adox = CreateObject("ADOX.Catalog")
adox.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & txtFolder.Text & txtFileName.Text & ".mdb" & _
"Jet OLEDB:Engine Type=5;")

I got this message
System.Runtime.InteropServices.COMException
NewDatabase is can not be used now
 
U¿ytkownik "yonggangwang said:
I try it, but it's not work.
adox = CreateObject("ADOX.Catalog")
adox.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & txtFolder.Text & txtFileName.Text & ".mdb" & _
"Jet OLEDB:Engine Type=5;")

Where is semicolon after database path (before "Jet OLEDB...")? :-) And
please write expression: txtFolder.Text & txtFileName.Text & ".mdb" in
debugger - I'm not sure if the fullpath is correct (maybe "\" is missing).

Regards,
Grzegorz
 
U¿ytkownik "yonggangwang said:
I try it, but it's not work.
adox = CreateObject("ADOX.Catalog")
adox.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & txtFolder.Text & txtFileName.Text & ".mdb" & _
"Jet OLEDB:Engine Type=5;")

I'm sorry but I have forgot semicolon after database path (before "Jet
OLEDB...").
And maybe there are any other problem with ADOX library - try, instead using
late binding to add reference to ADOX Library.

Below is working example (semicolon added):
Module Module1

Sub Main()
CreateDb("E:\My folder\My data.mdb")
End Sub

Public Function CreateDb(ByVal path As String)
Dim adox As Object
adox = CreateObject("ADOX.Catalog")
adox.Create("Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=" + path + _
";Jet OLEDB:Engine Type=5;")
End Function
End Module

Regards,
Grzegorz
 
Back
Top