简体   繁体   中英

How to filter data using datetime picker?

I use Date as datatype in MySQL server and insert mydate as:

datetimepicker1.value.ToString("yyyy-MM-dd")

It was successfully inserted, but when I search the data using a query like:

SELECT *
FROM Customers
WHERE CDate BETWEEN datetimepicker1.Value.ToString("yyyy-MM-dd")
                AND datetimepicker2.Value.ToString("yyyy-MM-dd");

It returns zero rows as result.

You forgot to use quote . Try this :

string.Format(
    "SELECT * FROM Customers WHERE CDate BETWEEN '{0}'AND '{1}'", 
    dateTimePicker1.Value.ToString("yyyy-MM-dd"),
    dateTimePicker2.Value.ToString("yyyy-MM-dd")
);

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