string SqlStr = string.Format("insert into O_Tracker " +
"(order_id,client_name,job_name,note_,s_date,e_date,paid,pickup_status,sub_orders) values " +
"({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')"
,s.Order_Id, s.Client_Name, s.Job_Name, s.Note, s.Start_Date,
s.End_Date, s.Paid, s.Ready2Pickup, subOrdersPath);
I keep getting this error from the debugger:
Syntax error (missing operator) in query expression
I just can't figure it out what's wrong in here. thanks for your help in advance.
UPDATE: I've changed the code to a format with parameters and got "mismatch criteria expression access" error.
string SqlStr ="insert into O_Tracker " +
"(order_id,client_name,job_name,note_,s_date,e_date,paid,pickup_status,sub_orders) values(@order_id,@client_name,@job_name,@note_,@s_date,@e_date,@paid,@pickup_status,@sub_orders)";
OleDbCommand cmd = new OleDbCommand();
cmd.Parameters.AddWithValue("@order_id", s.Order_Id);
cmd.Parameters.AddWithValue("@client_name", s.Client_Name);
cmd.Parameters.AddWithValue("@job_name", s.Job_Name);
cmd.Parameters.AddWithValue("@note_", s.Note);
cmd.Parameters.AddWithValue("@s_date", s.Start_Date);
cmd.Parameters.AddWithValue("@e_date", s.End_Date);
cmd.Parameters.AddWithValue("@paid", s.Paid);
cmd.Parameters.AddWithValue("@pickup_status", s.Ready2Pickup);
cmd.Parameters.AddWithValue("@sub_orders", subOrdersPath);
try
{
cnn.Open();
cmd.Connection = cnn;
cmd.CommandText = SqlStr;
cmd.ExecuteNonQuery();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cnn.Close();
}
Summary
Had a problem to add to a specific table field a file path. the guys here noticed that my code is vulnerable to SQL injection so i've done as their suggested and fixed my code.
another problem occurred after that and simply fixed it because the date field were not match.
Thanks all for you help! :)