views:

564

answers:

2

I cannot save data in access 2007. I tried the following:

  • Add a password to my DB; didn't work
  • Saved the db as a 2003 file; didn't work

Here is my code:

public bool ExecuteUDI(string query)
{
    Command = new OleDbCommand();
    Command.Connection = Connection;
    Command.CommandText = query;
    Command.CommandType = System.Data.CommandType.Text;
    try
    {
        // Open connection
        Open();

        if (Command.ExecuteNonQuery() != -1)
            return true;
        else
            return false;
    }
    catch (Exception e)
    {
        mError = "ExecuteUDI - " + e.Message;
        return false;
    }
    finally
    {
        // Always close connection
        Close();
    }
}

When I add breakpoints, I see my query looks good:

INSERT INTO DVD (Titel) VALUES ('Elegy')

I don't get any errors, but the affected rows is 0. How come? I dont understand..

+1  A: 

Where is your mdb file located in relation to your code? I have had issues in the past that having the mdb file in the project folder will in essence create a local copy of the db in memory when the app is running, but nothing is actually written back to the mdb in the folder...

I recommend putting the mdb file outside your project's folder. That should work.

Dan Appleyard
A: 

this's working fine.thns a lot

Mhamad