Home > database >  OleDb exception 0x80040e14 when trying to perform INSERT INTO
OleDb exception 0x80040e14 when trying to perform INSERT INTO

Time:11-22

I got this exception when I'm trying to perform the INSERT INTO command:

The Exception Image is here

This is my code:

private void AddQuiz_Button_Submit_Click(object sender, EventArgs e)
{
    // Connection when button is clicked 
    OleDbConnection myConnection = GetConnection(); 

    string myQuery = "INSERT INTO  QuestionBank (Question, Choice A, Choice B, Choice C, Choice D, Category, Correct Answer) VALUES ('"   AddQuiz_RichTextBox_Question.Text   "' , '"   OptionA_TextBox.Text   "' , '"   OptionB_TextBox.Text   "' , '"   OptionC_TextBox.Text   "' , '"   OptionD_TextBox.Text   "' , '"   AddQuiz_Category_Listbox.Text   "' , '"   AddQuiz_ListBox_Answer.Text   "')" ; //SQuery statement 

    OleDbCommand myCommand = new OleDbCommand(myQuery, myConnection);

    try
    {
        // Opening connection
        myConnection.Open(); 

        AddQuiz_Label_CheckConnection.Text = "Connection Successful";
        // Execute the query 
        myCommand.ExecuteNonQuery(); 

        MessageBox.Show("Question saved");
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception in DBHandler"   ex); 
    }
    finally
    {
        // Close connection 
        myConnection.Close(); 
    }
}

CodePudding user response:

I seen that 800xxxx message. In near all cases it means your project is running at the wrong bit size for the installed version of Access.

If you cpu setting is "Any", then you need to change the project settings to x86.

Give that a try.

So this setting:

enter image description here

And then in configuration manager - create a new setting for x86

enter image description here

So new config, and then:

Change dropdown to x86 - and yes, you can accept the default "Copy settings from"

You now have this:

enter image description here

Then close button - and you now have this:

enter image description here

And of course the reverse is also true - if you running office x64, then force the project to x64 and again do not use "any".

CodePudding user response:

The syntax error is caused by the spaces in your field names. Such names must, in Access SQL, be bracketed:

string myQuery = "INSERT INTO  QuestionBank (Question, [Choice A], [Choice B], [Choice C], [Choice D], Category, [Correct Answer]) VALUES ('"   AddQuiz_RichTextBox_Question.Text   "' , '"   OptionA_TextBox.Text   "' , '"   OptionB_TextBox.Text   "' , '"   OptionC_TextBox.Text   "' , '"   OptionD_TextBox.Text   "' , '"   AddQuiz_Category_Listbox.Text   "' , '"   AddQuiz_ListBox_Answer.Text   "')" ; //SQuery statement 

That said, do learn to use parameters - much cleaner and easier to debug.

  • Related