Hi there, i am deeply troubled as my application runs successfully and adds new entry to the table and i can see that via datagridview.

but as soon as the application closes and i check the database all is gone. there is no entry in the database. kindly see my code.

private void btnUpdateEntry_Click(object sender, EventArgs e)
        {
            string update_cmd = "INSERT INTO SMO_Table" + "(field1,field2,field3,field4)" + "VALUES( 36,'ali','11:15','17:40')";

            OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\SMO_DB.mdb");

            OleDbCommand aCommand = new OleDbCommand(update_cmd, aConnection);
            
            aConnection.Open();
            
            try
            {
                aCommand.ExecuteNonQuery();
             }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
             aConnection.Close();
            
dataGridView1.Enabled = true;
            this.sMO_TableTableAdapter.Fill(this.sMO_DBDataSet.SMO_Table);

the above code runs successfully but actually there is no entry in the database. why is this so?

Regards,

There are two copies of your database. One which is located in project-solution folder and another is at debug\bin folder. The path you mentioned is target to debug\bin folder.

Database file added with project consider as a resource and VS creates a copy of database to the debug\bin folder.

To control such a thing:
1. Select database file from solution explorer
2. Set Copy to output directory property from properties windows.

There are two copies of your database. One which is located in project-solution folder and another is at debug\bin folder. The path you mentioned is target to debug\bin folder.

Database file added with project consider as a resource and VS creates a copy of database to the debug\bin folder.

To control such a thing:
1. Select database file from solution explorer
2. Set Copy to output directory property from properties windows.

Thank you problem solved.

there is another request for you how can i lock this database so that no one can change the contents after the program is close.

my idea is to encrypt it.

i am looking for your comments. again thanks for your help

Regards,
Jincom

Assign username and password to your access database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.