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();
我在上面的查询中收到错误。但是得到同样的结果,Plz帮助它
答案 0 :(得分:0)
尝试使用参数化查询
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();