When Iam inserting into tables...i get some errors.
Tried many method....but it did not work...please help!
I did the same code for another table and it gets added... i can not find the error.
For Following code it gives "Number of query values and destination fields are not the same"
ConnectionToDB();
string sql = "INSERT INTO TW100NEL VALUES('"+pl+"','"+desc+"',"+grp+","+qty+",'"+unit+"')";
comm.CommandType = CommandType.Text;
comm.CommandText = sql;
comm.Connection = conn;
conn.Open();
comm.ExecuteNonQuery();
MessageBox.Show("Successfully Added!");
conn.Close();
When i write like following, it give error :"Syntax error in INSERT INTO statement"
string sql ="INSERT INTO TW100NEL(ComponentNumber,ObjectDescription,Group,Quantity,Unit) VALUES(@pl,@desc,@grp,@qty,@unit)";
comm.Parameters.AddWithValue("@pl", pl);
comm.Parameters.AddWithValue("@desc", desc);
comm.Parameters.AddWithValue("@grp", grp);
comm.Parameters.AddWithValue("@qty", qty);
comm.Parameters.AddWithValue("@unit", unit);
comm.CommandType = CommandType.Text;
comm.CommandText = sql;
comm.Connection = conn;
conn.Open();
comm.ExecuteNonQuery();
MessageBox.Show("Successfully Added!");
conn.Close();
I have checked all rows..it is correct and whatever value i am entering goes to rows which are editable.
I am working on accdb.
Following query works well in accdb query design :
INSERT INTO TW100NEL VALUES('1234','zzzzzzz',4,2,'PC');
I did not show code of connections because it is working well for other sql.
Thank you in advance.