views:

30

answers:

1

How can I create access 2000-2003 file using C# WPF and add tables in, data in and perform queries on it?

I`m using MS Visual Studio 2010

this is what I`ve been able to accomplish:

        OleDbConnection conn = new OleDbConnection();
        string myDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
        string dbPath = myDir + @"\EmpMan.mdb";
        MessageBox.Show(myDir);
        if (!File.Exists(dbPath))
        {
            //Here I want my program to create an Access DB File in the dbPath location...
        }
        conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath + ";Password=EmpMan";
        try
        {
            conn.Open();
        }
        catch (OleDbException ex)
        {
            MessageBox.Show("Error: " + ex.Errors[0].Message);
            Application.Current.Shutdown();
        }
A: 

Here is an example of how to programatically create an access database using c#. I found it by saerching for "programmatically create access database c#" using google. Google is your friend, I would recomend in future that and you should use it first and post here if you can't find what you need.

Ben Robinson
@Ben Robinson: I`ve tried this after searching google ... but it didn`t work. I can`t find this version of the ADOX as I`m using the VS 2010 not the 2003 as they said!! so is there any other way to do so without the ADOX or anything compatible with the VS 2010?
sikas
Ben Robinson
well, I`m creating an application that will deal with password-protected access 2000-2003 database. So I want the application, when launched, check weather the db file exists or not, if exists, the app starts, else the file is created then the app starts ...
sikas
Why not simply distribute a blank database with the application, if there is no existing database then take a copy of the blank one and use that as the working copy. That way you can have a default workgroup file as well and you don't have to set up whatever your base set of users and permsions are.
Ben Robinson
@Ben Robinson: my guess is that he means a database password, not Jet user-level security. Basically, database passwords are a complete waste of time, security theater, not actually worth anything. But even with the template, the template could be copied, and then apply the database password (however that's done in code -- I wouldn't know how, since I think it's a waste of time...).
David-W-Fenton