The way SQL server save the datatime format and in .NET application are not the same. So, you may need to convert your datetime value to appropriate datetime value that is passed from your datetimepicker. For example the datatimepicker return the picked date
mm/dd/yyyy
format, so your query should look like
query = "SELECT * " +
"FROM tableName " +
"WHERE (CONVERT(nvarchar(20),DateSpent,101) BETWEEN '" + dateFrom + "' AND '" +
dateTo + "') " +
"ORDER BY CONVERT(nvarchar(20),DateSpent,101)";
For more CONVERT SQL function please look.
SQL Server CONVERT() Function[
^]
BTW, please use parameterized query for your application. Working with plain SQL statement will expose your application for
SQL Injection[
^].
I hope this will help you well.