0

Hi there,
I have a problem in datetimepicker in the interface in C#. I have restricted the user for entering a date that has passed by the below code
dpSignedSO.Value = DateTime.Today;
dpSignedSO.MinDate = DateTime.Today;
but when the date is entered as 7/20/2010 and this is being saved to the database. When I try to get the values from the database the next day it gives an error message saying “ArgumentOutOfRangeException” which further explains as “Value of '7/20/2010 1:43:25 PM' is not valid for 'Value'. 'Value' should be between 'MinDate' and 'MaxDate'.
Parameter name: Value”

How can I avoid this situation.


is there an way I can track if the datetime picker value is not changed in the interface to store a garbage value in the database for the datetimepicker??

how can i solve this???

thanxxxxx

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by menakaa
0

When storing the value in the DB use dpSignedSO.Value.Date to only capture the date portion (actually the time is set to 00:00:00).
(You could also do the same when setting dpSignedSO.Value from the DB just to be certain it has no time part.)

0

When storing the value in the DB use dpSignedSO.Value.Date to only capture the date portion (actually the time is set to 00:00:00).
(You could also do the same when setting dpSignedSO.Value from the DB just to be certain it has no time part.)

Hey
I am not worried about the time part but the thing is I have validated the datetime picker so that the user can’t enter a date that has passed, so if the user dosen’t select a value the current date will be saved in the database. But when the data is being viewd the next day there is a error occurring because the database value is yesterdays date and the validation is restricted for not letting the user to enter a date that has passed the todays date. So there is am argument out of range exception. So how can I avoid it??

Thanx
Hope you got my question

0

You could change the value of the MinDate property depending upon if the data is new or old, rather than have a single MinDate.

The order of setting MinDate and Value is important.
When adding a new record.

dpSignedSO.Value = DateTime.Today;
dpSignedSO.MinDate = DataTime.Today;

When loading an old record.

dpSignedSO.MinDate = DataTime.MinValue;
dpSignedSO.Value = <Date from DB>;

How you keep track if it is an old record or a new record is down to you.

0

If you want to insert date value into sql
using the code like this

'"&datetimepicker1.value.tostring&"'

also able to view from sql db in proper format

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.