2

is it possible to create access database on a c:\ drive on the click event of the button ???

3
  • Create from scratch? Or from an existing one? What exactly are you trying to achieve? Commented Apr 29, 2011 at 6:17
  • possible duplicate of How do I create a Microsoft Jet (Access) database without an interop assembly? Commented Apr 29, 2011 at 6:23
  • Depends on where on the C: drive. In the root, you'd likely not be able to because of restrictions on write permissions. Commented Apr 30, 2011 at 19:39

2 Answers 2

2

Yes you can. But this is a duplicate.

To create an Access database from C# code use ADOX: - How to create an Access database by using ADOX and Visual C# .NET:

using System;
using ADOX;

namespace ConsoleApplication1
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            ADOX.CatalogClass cat = new ADOX.CatalogClass();

            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
                   "Data Source=D:\\AccessDB\\NewMDB.mdb;" +
                   "Jet OLEDB:Engine Type=5");

            Console.WriteLine("Database Created Successfully");

            cat = null;

        }
    }
}

[To create an SQL Server database from C# code use SQL Server Management Objects (SMO).]

Sign up to request clarification or add additional context in comments.

1 Comment

He is looking to create an access database, not SQL Server.
2

You could use office automation to create a new database and save it to the local drive.

Or if you have a template of a database you could use that and copy it to the local drive.

Without knowing exactly what you are trying to do, a more useful answer can't be given.

1 Comment

Why would anybody use automation to create it when you've got Jet available on every copy of Windows since 2000? +1 for the template, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.