Solved

c# ExecuteNonQuery not inseting a row into a access database

Posted on 2009-07-01
4
329 Views
Last Modified: 2013-12-17
Hi

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

HELP PLEASE
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
            command.ExecuteNonQuery();
 
            // Close the database connection
            CloseConnection(ref Connection);
        }
        
    }

Open in new window

0
Comment
Question by:delta_v
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24757150
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 ...
0
 
LVL 1

Author Comment

by:delta_v
ID: 24757163
i am running select querys off the db with info i am putting in to the db i am checking
0
 
LVL 8

Expert Comment

by:InternalStatic
ID: 24759221
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,
Nate
0
 
LVL 1

Author Closing Comment

by:delta_v
ID: 31598907
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
InputLanguage 1 25
How come this regular expression allows "e"? 14 35
Call Controller Action Method from ASPX 2 13
Help with preventing selection from a combobox 11 22
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question