Solved

c# ExecuteNonQuery not inseting a row into a access database

Posted on 2009-07-01
4
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

695 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