I have an local database in Visual Studio (SQL Server Compact Edition), with a table with a few columns. One of those columns has the datatype DateTime
. When I to insert a row I add the date/time value by using DateTime.Now
in C#.
When I do a
SELECT * FROM ...
I see that the DateTime format is 7-5-2012 11:41
.
But now I need to do a select query with a where clause, so that the result is between certain days. I can't find a way to filter between dates/times, when I use the DateTime.Now
function to set the between I get 0 rows back. But also when I set the between manually by setting
WHERE date BETWEEN '7-5-2012 00:00' AND '8-5-2012 00:00'
and even then I get 0 values back.
I also tried to do it with SqlCeCommands
but gives is the same problem, 0 rows back.
Does anyone what I'm doing wrong or how I get this to work?
Thank you in advance!
May be you have wrong date format, you should use query command parameters:
command.CommandText = "SELECT * FROM ... WHERE date BETWEEN @lowb AND @highb";
command.Parameters.Add( "@lowb", SqlDbType.DateTime, new DateTime(...));
command.Parameters.Add( "@highb", SqlDbType.DateTime, new DateTime(...));
尝试这个:
"..spRis_GetListaDocs @DateFilter = '" + Convert.ToDateTime(txtDate.Text).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.