Microsoft Access Database, Insert, Update and Delete in Visual Studio with C#
<p>I'm trying to insert a row to a table in Microsoft Access Database via Visual Studio 2015 an c#.</p>

<p>the Scenario is: a class called: <code>QuestionData</code> and a class <code>Question</code>. A table <code>exams</code>, and table <code>questions</code>.</p>

<p>my code is:</p>

<pre><code>public static bool addQuestion(QuestionData quesData)
    {
        if (quesData == null || quesData.question == null) { return false; }
        List&lt;QuestionData&gt; questionsData = new List&lt;QuestionData&gt;();

        string connetionString = null;
        OleDbConnection cnn;
        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;";
        cnn = new OleDbConnection(connetionString);
        try
        {
            string insertCmd = "INSERT INTO questions (exam_id, [name], question_text, withImage, question_correctAnswer, answer_1, answer_2, answer_3, answer_4) VALUES (@exam_id, @name, @question_text, @withImage, @question_correctAnswer, @answer_1, @answer_2, @answer_3, @answer_4)";
            OleDbCommand cmd = new OleDbCommand(insertCmd);

            cmd.Parameters.Add("@exam_id", OleDbType.Numeric).Value = quesData.examId;
            cmd.Parameters.Add("@name", OleDbType.LongVarChar).Value = quesData.question.getName();
            cmd.Parameters.Add("@questionText", OleDbType.LongVarChar).Value = quesData.question.getQuestionText();
            cmd.Parameters.Add("@withImage", OleDbType.Boolean).Value = quesData.question.isImageEnabled();
            cmd.Parameters.Add("@question_CorrectAnswer", OleDbType.Numeric).Value = quesData.question.getCorrectAnswer();
            cmd.Parameters.Add("@answer_1", OleDbType.LongVarChar).Value = quesData.question.getAnswer(0);
            cmd.Parameters.Add("@answer_2", OleDbType.LongVarChar).Value = quesData.question.getAnswer(1);
            cmd.Parameters.Add("@answer_3", OleDbType.LongVarChar).Value = quesData.question.getAnswer(2);
            cmd.Parameters.Add("@answer_4", OleDbType.LongVarChar).Value = quesData.question.getAnswer(3);

            cmd.Connection = cnn;
            cnn.Open();
            int result = cmd.ExecuteNonQuery();
            cnn.Close();

            return true;
        }

        catch (Exception ex)
        {
            MessageBox.Show("Exception: \n Source: " + ex.Source + "\n Message: " + ex.Message);
            cnn.Close();
            return false;
        }
    }
</code></pre>

<p>Everything works fine, with no compiling or run-time errors, and <code>cmd.ExcuteNonQuery();</code> line returns positive value <code>(1)</code>, but nothing happens to database file. but <code>Read Query</code> works fine and does its job.</p>

<p>I searched google, and tried every single solution on the internet, but no thing changed the result.</p>

<p>I appreciate any help, and any guide to solve the problem. </p>