none
Having problem in inserting data into MS Access database. getting error " command text was not set for the command object" RRS feed

  • Question

  • string connParam = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\KYC.accdb;Encrypt Password=False";
                OleDbConnection conn = new OleDbConnection(connParam);
                OleDbCommand cmd = conn.CreateCommand();
                conn.Open();
                cmd.Connection = conn;
                string str = "insert into Data Entry(FName, MName, LName, F/HF Name, F/HM Name, F/HL Name, Address, Country, State, District, ZipCode, Gender, Blood Group, Email ID" +
                             "Nationality, Remarks) values ('" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text +
                             "','" + textBox8.Text + "','" + textBox9.Text + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text + "','" + textBox13.Text + "','" +
                             textBox14.Text + "','" + textBox15.Text + "','" + textBox16.Text + "','" + textBox2.Text + "','" + textBox17.Text + "')";
                cmd.CommandText = "";
                int temp = cmd.ExecuteNonQuery();
                if (temp > 0)
                {
                    MessageBox.Show("Data Saved");
                }
                conn.Close();
    Sunday, June 9, 2013 5:01 PM

Answers

  • Hello,

    The error stems from

    cmd.CommandText = "";

    Looks like it should be

    cmd.CommandText = str;


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Monday, June 10, 2013 11:07 AM