Setting DateTime as a SqlDataSource parameter for Gridview?

You're creating parameters which specify a DateTime type, but you're giving them strings as values. Don't do that - you shouldn't convert to/from strings unless you really have to. There may be other problems too, but start off by removing the ToString calls.

Up vote 0 down vote favorite share g+ share fb share tw.

Hey I would like to display certain data with my stored procedure for the last 30 days. Here is what I have done (aspx. Cs file): protected void Page_Load(object sender, EventArgs e) { DateTime toDate, fromDate; toDate = DateTime.

Now; fromDate = toDate. Subtract(new TimeSpan(31, 0, 0, 0)); SqlDataSource1. SelectParameters.

Add("fromDate", DbType. DateTime, fromDate.ToString()); SqlDataSource1. SelectParameters.

Add("toDate", DbType. DateTime, toDate.ToString()); } here is my aspx file " SelectCommand="procCustomer_SelectbyCreationDate" SelectCommandType="StoredProcedure"> when I test this my screen comes up blank (other than the masterpage elements) and no errors. Any ideas?

C# asp.net gridview sqldatasource link|improve this question asked Jan 9 at 10:55user105136453 40% accept rate.

You're creating parameters which specify a DateTime type, but you're giving them strings as values. Don't do that - you shouldn't convert to/from strings unless you really have to. There may be other problems too, but start off by removing the ToString calls: SqlDataSource1.

SelectParameters. Add("fromDate", DbType. DateTime, fromDate); SqlDataSource1.

SelectParameters. Add("toDate", DbType. DateTime, toDate); 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.

If I remove the toString() I get following error "The best overloaded method match for 'System.Web.UI.WebControls. ParameterCollection. Add(string, System.Data.

DbType, string)' has some invalid arguments" – user1051364 Jan 9 at 11:30 also, removing the parameters from the aspx file seemed to solve the problem... at least I get some data on the screen now. I had to use the toString() conversion though... – user1051364 Jan 9 at 11:32.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions