This is a migrated thread and some comments may be shown as answers.

Binding RadTimePicker to SQL 2008 Time Data Type

2 Answers 138 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 05 Apr 2011, 10:07 AM
How can I bind the RadTimePicker to a SQL Server 2008 Time field? It would see the logical choice of control, but when I do, I get the error:-
Cannot convert value of parameter 'Time' from 'System.DateTime' to 'Nullable<System.TimeSpan>' 

Is there a work around,or plans to support this in the future? 

2 Answers, 1 is accepted

Sort by
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 05 Apr 2011, 10:23 AM
I've solved the issue, but it's a hack. It would be much nicer to have the RadTimePicker support TimeSpans directly. Is this a planned update? If not, can it be requested?

The solution was to intercept teh form view insert, using the ItemInserting event, and change the datatype:-

protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
       {
            
           //turn datetime to timespan
           DateTime ds = (DateTime)e.Values["Time"];
           TimeSpan ts = ds.TimeOfDay;
           e.Values["Time"] = ts.ToString();
       }
0
Vasil
Telerik team
answered on 08 Apr 2011, 09:46 AM
Hello AP,

You can see an example how to bind datepicker to database here:
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/databinding/defaultcs.aspx
Actually it uses pretty much the same workaround. But currently we are not planning to change this behavior. It is a general issue with binding nullable types from the database. The DatePicker itself uses DateTime type which is standard type in .Net. And this ensures that all users could easily manipulate with it and bind it to various datasources, even if sometimes they will need to cast it first.

Regards,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Vasil
Telerik team
Share this question
or