|
Rank: Newbie Groups: Member
Joined: 7/29/2008 Posts: 9
|
Hi, I'm using the web-based DateTime picker but I faced the following problem.
When I change the date in the control and then save changes to database - all fine. But when I load the record and I want to remove the date - it just doesn't work - system continues to save the previously enterred date.
Am I missing something?
Dexter
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi, We can't think of anything that can cause that on the DatePicker. You might want to test it in a separate page without the database. Try the following steps: 1. Place a DatePicker, a Label and a Button in the form; 2. In your Page_Load, set the DatePicker's SelectedDate property. Make sure you put such code inside If Not Page.IsPostBack. For example:
Code: Visual Basic.NET
If Not Page.IsPostBack Then
DatePicker1.SelectedDate = System.DateTime.Now
End If
3. Run the page and clears the DatePicker; 4. Click the Button to submit the page; 5. In your Button's Click handler, set the Label's Text to the DatePicker's SelectedDate.ToString(); You should see the Label displays "1/1/0001 12:00:00 AM". This is DateTime.MinValue. It means the DatePicker is empty. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 7/29/2008 Posts: 9
|
Thank you about your reply. I fixed the problem - however I still think that the picker have a strange behavour when we deal with empty dates.
The problem is that the picker's min value is 0001-01-01 - this is by default, but only when picker is bound to a date that is 0001-01-1 then it shows as " \ \ " which is OK. However, the minimum datetime value that SQL can store/retrieve is 1753-01-01!? In fact, if I want to delete the date from the picker then .NET stores 0001-01-01 which is incorrect SQL date. If I put 1753-01-1 as min value for the date time picker then - surprise! - such date is not empty for the control and it is shown in the control instead of showing " \ \ " :(
So, when I retrieve the date from DB i have to check if it is any date that is not correct for our needs (I chosed 1753-01-1 because its the min SQL date value) and if I have retrieved such date I then modify it to 0001-01-1, so control is then displaying correct value of " \ \ ".
Saving of such date is a pain too because I have to modify the date again to 1753-01-01!
This is a unnecessery work by my means :(
We are using the trial version of the control and we intend to use licensed version in the future. But such behavour is strange and needs considetation.
Oh, and one problem more - DatePicker can't handle NULL dates! It returns exception.
Dexter
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi Dexter,
Consider using SelectedDateString or SelectedDateStringInvariant. SelectedDate is a DateTime value and it has no null values. You will still need to convert string value to date time value/DbNull value if necessary.
.NET and SQL Server are two different worlds, other DB engine may have different rules than SQL Server, so it is not practical to implement our controls to follow SQL Server's rule. Sorry about that!
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 7/29/2008 Posts: 9
|
SelectedDate is the only bindable property I can use, I don't see a property named SelectedDateString.
I agree SQL has its own style but I'm still wornderred why 0001-01-01 is the date choosed to be a "blank" date?! I don't find it practical at all. This means you have to put your own code whatever DB engine you are using.
Dexter
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,193
|
Hi,
I believe whatever value we choose you have to put your code anyway because DateTime does not have a Null value. So choosing what value really doesn't matter much here. Our priority is to produce a DatePicker to give a DateTime value and that's it. If you want to use it with X DB engine, you will be responsible to figure out how to make X DB engine happy. And if you want to use it with Y DB engine, you will be responsible to figure out how to make Y DB engine happy. From our point of view, we can't customize our product towards one DB engine so that it works one way with X DB engine and another way with Y DB engine. That will make user of X DB engine user happy but Y DB engine extremely unhappy and makes the whole thing unnecessary complicated.
Thanks
|
|