c# ExecuteNonQuery not inseting a row into a access database


i am trying to insert a row into a database using the   OleDbConnection and   OleDbCommand

the sql command works fine when i run it in ms access

when i run the cod enothing happens

no data inserted, no error

public void WriteRegisterRecords(ArrayList Scouts, int MeetingID)
        // Loop through all scouts in the array
        foreach (Scout ScoutRec in Scouts)
            string sqlQuery = "";
            // Build the sql query
            sqlQuery += "INSERT INTO tblRegister (MeetingID, ";
            sqlQuery += "                         ScoutID, ";
            sqlQuery += "                         Attendence) ";
            sqlQuery += "VALUES (1, 1, 0);";
            OleDbConnection Connection = CreateAndOpenConnection();
            // Write the data
            //ExecuteDatabaseWrite(ref Connection, sqlQuery);
            // Create the command linking the connection and the SQL to be run
            OleDbCommand command = new OleDbCommand(sqlQuery, Connection);
            // Execute the query
            // Close the database connection
            CloseConnection(ref Connection);

Open in new window

Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
the code is correct.

so, you must be checking/inserted into different databases.
note that ms access sometimes has some delay between the insert vs the select ...
delta_vAuthor Commented:
i am running select querys off the db with info i am putting in to the db i am checking
Nate FeinbergRelationship ManagerCommented:
Access can sometimes be very picky with its queries. Try removing the spaces you've shoved into your string. Also, if any of those fields you're inserting are of type Autonumber, it usually won't work, though I've found this rather inconsistent. If any of the data types for the fields are Text, you'll need to surround the values in single quotes, too.
Hope this helps,
delta_vAuthor Commented:
Unfortunately the real problem occurred between the computer and the chair.

When a C# program is compiled it moves the database into the debug/bin directory and does not copy it back.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.