Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
HI

How WE can Create mdb file with VB.NET?


tanx
Posted

One way is using Interop.Access in .NET framework and another way is using ADOX library .

Here is the code which is extracted from here :
http://stackoverflow.com/questions/155848/how-do-i-create-a-microsoft-jet-access-database-without-an-interop-assembly[^]

C#
if (!File.Exists(DB_FILENAME))
{
    var cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_FILENAME;

    // Use a late bound COM object to create a new catalog. This is so we avoid an interop assembly. 
    var catType = Type.GetTypeFromProgID("ADOX.Catalog");
    object o = Activator.CreateInstance(catType);
    catType.InvokeMember("Create", BindingFlags.InvokeMethod, null, o, new object[] {cnnStr});

    OleDbConnection cnn = new OleDbConnection(cnnStr);
    cnn.Open();
    var cmd = cnn.CreateCommand();
    cmd.CommandText = "CREATE TABLE VideoPosition (filename TEXT , pos LONG)";
    cmd.ExecuteNonQuery();

}


and if you don't want use ADOX read this article to get some clues :
http://support.microsoft.com/kb/317114[^]

But generally speaking generating MDB files in runtime is somehow an immature approach...

Good Luck
 
Share this answer
 
Comments
sara.solati68 23-Nov-11 7:30am    
If I use the first method, Access program must be installed?

and tel me more about ADOX?!!!
Amir Mahfoozi 23-Nov-11 8:56am    
Yes if you use the first method you must have Access installed but I'm not sure about ADOX but I think it does exist by default on every windows operating system. and you can read more about ADOX here : http://msdn.microsoft.com/en-us/library/windows/desktop/ms677200%28v=vs.85%29.aspx a sentence from there : "(ADOX) is an extension to the ADO objects and programming model. ADOX includes objects for schema creation and modification, as well as security" Good Luck
sara.solati68 23-Nov-11 10:12am    
Thank you, really.
Amir Mahfoozi 23-Nov-11 11:18am    
You're welcome.
RaisKazi 23-Nov-11 13:03pm    
Comprehensive Answer. 5ed.
I had seen these before. And I could not use them.

If you may introduce other sources.or: Please write the code.

I am working with Microsoft Visual Studio 2008.(WAP)
 
Share this answer
 
Comments
Mehdi Gholam 23-Nov-11 13:24pm    
Use the comments do not post solutions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900