Solved

c# ExecuteNonQuery not inseting a row into a access database

Posted on 2009-07-01
4
331 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…

730 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