Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:53:35+00:00 2026-06-04T02:53:35+00:00

I am using an OleBdCommand To Insert A record into a Db, but the

  • 0

I am using an OleBdCommand To Insert A record into a Db, but the update never persists.

Here is the Code

    public void InsertCandidate(XElement element, ref OleDbDataAdapter adapter, OleDbConnection sqlConnStr)
    {
        if (sqlConnStr.State == ConnectionState.Broken || sqlConnStr.State == ConnectionState.Closed)
            sqlConnStr.Open();

        try
        {
            string query = "Insert Into Candidate Values(@priKey, @Name, @LName, @Phone, @Add)";
            OleDbCommand InsertCandidate = new OleDbCommand(query, sqlConnStr);
            InsertCandidate.Parameters.AddWithValue("priKey", element.Attribute("CAND_NUM").Value);
            InsertCandidate.Parameters.AddWithValue("Name", element.Attribute("CAND_FNAME").Value);
            InsertCandidate.Parameters.AddWithValue("LName", element.Attribute("CAND_LNAME").Value);
            InsertCandidate.Parameters.AddWithValue("Phone", element.Attribute("CAND_PHONE").Value);
            InsertCandidate.Parameters.AddWithValue("Add", element.Attribute("CAND_ADDRESS").Value);
            InsertCandidate.ExecuteNonQuery();
        }
        catch (OleDbException ex)
        {
            MessageBox.Show("A Error occured whilst trying to execute the command.\n" + ex.Message);
        }
    }

NO exceptions, errors or anomalies are generated!

Any Advice

M


I even tried this.

            //InsertCandidate.ExecuteNonQuery();
            adapter.InsertCommand = InsertCandidate;
            adapter.InsertCommand.ExecuteNonQuery();

*Thanks Every One *

Aiden’s Code Worked, but i should have read Tony’s Post Better hence i accepted his answer (he said it first)

Kind Regards

And Thanks Once Again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:53:37+00:00Added an answer on June 4, 2026 at 2:53 am

    Have you executed your SQL statement in isolation from your code to make sure it works?

    As you have not posted the table definition it could be because you are not specifying the fields in your insert statement.

    I’m not an OLEDB expert but all the examples I can find on the net use question marks in place of parameters. Try the SQL statement like this:

    string query = "Insert Into Candidate Values(?, ?, ?, ?, ?)";
    

    Update

    Looking at the documentation for the OleDBCommand it will only throw an InvalidOperationException and not an OleDbException in the event of an error. You should add this exception handler and see if that gives you any more information.

    Alternatively change your exception hanndler to catch the generic Exception type to see if you even get an exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using OleDbCommand.ExecuteNonQuery() to insert data into the database: ObjCommand = New OleDbCommand
I was trying to insert values into an Access database using a parameterized query:
I'm trying to insert a System.DateTime into an Access database using a parameterized OleDbCommand
Im currently using OleDBCommand.ExecuteNonQuery (repeatedly called) to insert as much as 350,000 rows into
I'm using ASP.NET/VB and I'm trying to insert a date and time into an
How do I insert data into a .dbf format database using SQL in Visual
I'm using an OleDbConnection, OleDbCommand, and OleDbDataReader to read a CSV file into a
Using LINQ on collections, what is the difference between the following lines of code?
Using a restful resource in Rails, I would like to be able to insert
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.