Solved

c# ExecuteNonQuery not inseting a row into a access database

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

911 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

21 Experts available now in Live!

Get 1:1 Help Now