简体   繁体   中英

syntax error missing operator in date and time query expression

cmd.CommandText = "SELECT * FROM " + TableName + " WHERE"
                                                + " [TIME_STAMP]=#" + TimeStamp.ToString("dd-MM-yyyy HH:mm") + "#"
                                                + " AND [Slave_Id]='" + SlaveUnitID
                                                + " AND [Parameter]='" + Param
                                                + "' AND [Status]='" + Status
                                                + "' AND [Reading]='" + Reading + "'";
                                dr = cmd.ExecuteReader();

I am getting error in the above query.Tried but getting the same, Plz help it out

Try to use parameterized query

conn.Open();
string query = "SELECT * FROM " + TableName + " WHERE [TIME_STAMP] =@date "
+" AND [Slave_Id]=@sid AND [Parameter] =@param  "
+" AND [Status] =@status AND [Reading] = @reading"
qlCommand cmd = new SqlCommand(query,conn);
cmd.Parameters.AddWithValue("@date", TimeStamp);
cmd.Parameters.AddWithValue("@sid", SlaveUnitID);
cmd.Parameters.AddWithValue("@param", Param);
cmd.Parameters.AddWithValue("@status", Status);
cmd.Parameters.AddWithValue("@reading", Reading );
dr = cmd.ExecuteReader();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM