2

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

Hemanth
  • 413
  • 7
  • 17
  • Create from scratch? Or from an existing one? What exactly are you trying to achieve? – Oded Apr 29 '11 at 06:17
  • possible duplicate of [How do I create a Microsoft Jet (Access) database without an interop assembly?](http://stackoverflow.com/questions/155848/how-do-i-create-a-microsft-jet-access-database-without-an-interop-assembly) – Mitch Wheat Apr 29 '11 at 06:23
  • Depends on where on the C: drive. In the root, you'd likely not be able to because of restrictions on write permissions. – David-W-Fenton Apr 30 '11 at 19:39

2 Answers2

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.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • 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. – David-W-Fenton Apr 30 '11 at 19:42
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).]

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541