Don't concatenate literals (date, text etc) to your SQL statements. Instead use
MySqlParameter[
^].
When that is done, set the proper datetime to the parameter as value and you should get correct results.
Addition:
Currently you have a query like:
SELECT * FROM `tbluser` where `date`<='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and `time`<='" + DateTime.Now.ToString("hh:mm") + "' and user='" + txtuser.text + "'"
What you should do is to use parameter (see the link I provided) so your query would look something like:
SELECT * FROM `tbluser` where `date`<= @date and `time`<=@time and user=@user"
After that modification you define proper values for all of the three parameters via C# (as in the example).
I'm not sure but it looks like you may actually store dates and times in the database as character information. If that is true, then you should correct the table structure and define a single
datetime
field in your table and use that instead. See:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html[
^]
If that is done your query could look something like:
SELECT * FROM `tbluser`
where datetimefield <= @datetimetosearch
and user=@user"
That would eliminate the problems for having the date and time information in separate fields and possibly conversion problems if you currently use character data type.