Solved

c# ExecuteNonQuery not inseting a row into a access database

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now