james james

james james

  • 1.7k
  • 409
  • 24.1k

Insert data into database error

Oct 21 2017 9:23 AM
I am getting an error while inserting data.
 
The error is "Number of query values and destination fields are not the same".
 
I have read alot about ppl missing some single qoutes but I must be overlooking them.
 
My code :
 
private void btn_Insert_Click(object sender, EventArgs e)
{
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Table values('" + txt_Date + "','" + txt_Units + "','" + txt_TimeOrd + "','" + txtTimeRec + "','" + txt_Panel + "', '" + txt_Box +"','" + txt_Name + "', '" + txt_Notes +"')";
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record inserted Successfully");
}
}
}

Answers (5)