EDIT: Even though an earlier version of this answer was accepted, it looks like I had misunderstood the parameter type used. The web controls ParameterCollection
looks somewhat awful.
I would suggest converting date values to a SQL format (much as that pains me, frankly - string conversions should be avoided as far as possible). For example:
SqlDataSource1.SelectParameters.Add("fromDate", DbType.DateTime,
fromDate.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
SqlDataSource1.SelectParameters.Add("toDate", DbType.DateTime,
toDate.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
(Change to yyyy-MM-dd
for date-only types.)
I haven't used SqlDataSource
myself, but it also looks like you're introducing the parameters twice - once in the markup, and once in the code. Given that you don't have the values in the markup (including in bindings), you may want to remove them from there - but I could be wrong on that front.
If your query isn't doing what you expect, you should check your database logs (or whatever tool is appropriate) to check what actual query is executing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…