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

Databind RadTimePicker to SQL Time Column

4 Answers 186 Views
Input
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 29 Jan 2010, 04:44 PM
I have a RadTimePicker in a RadGrid.  The grid is bound to a SqlDataSource which is connected to a SQL Server 2008 database table.  The table contains a column with a datatype of "time," which is not null.

When I attempt to bind a RadTimePicker to this time column, I receive the error 
System.InvalidCastException:Specified cast is not valid.

This is how I'm attempting to do the databinding:
<telerik:RadTimePicker ID="RadTimePicker1" runat="server" DbSelectedDate='<%# Bind("TimeMon") %>' /> 


Please advise if I am missing something, or if the time data type in SQL Server is too new, preventing me from doing this.  I am using RadControls for ASP.NET AJAX 2008.3 1314

Thanks!
Travis

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 04 Feb 2010, 07:53 AM
Hello Travis,

The code supplied looks correct, and should handle the task at hand. However, in order to further track the problem, it will be best if you open a formal support ticket and send us a small working project, demonstrating the setup, and the error you received. Upon reviewing it, we will advise you further.

Additionally, I suggest you review the following articles which elaborates on this subject:
Data Binding
Using RadDatePicker/RadDateTimePicker as editor in template column od RadGrid

Kind regards,
Pavlina
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Sean P. Jaeger
Top achievements
Rank 2
answered on 04 Feb 2010, 11:45 PM
I am having the exact same issue with setting the value of DbSelectedDate from the code behind:

 

radtmpkBackupTimeAddUpdate.DbSelectedDate = schedule.BackupTime; 

Where "BackupTime" is a SQL 2008 Time data type.

The error received is:

Specified cast is not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 64: 
Line 65:         radcmbClientAddUpdate.Items.FindItemByValue(keys["BackupClientID"].ToString()).Selected = true;
Line 66: radtmpkBackupTimeAddUpdate.DbSelectedDate = schedule.BackupTime;Line 67: 
Line 68:     }

Source File: c:\inetpub\wwwroot\Amex.Sdn.Aeln.BackupUtility\Default.aspx.cs    Line: 66
0
Pavlina
Telerik team
answered on 05 Feb 2010, 09:27 AM
Hi Sean,

Based on the information supplied I suspect that you are trying to bind non-DateTime value to RadTimePicker . However, in order to be sure, it would be best if you open a formal support ticket, and send us the problematic implementation, for  further review. We will test it locally, and get back to you with our findings.

Kind regards,
Pavlina
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Oscar
Top achievements
Rank 1
answered on 16 May 2012, 11:31 PM
I had the same problem when editing the RadGrid with RadTimePicker with column of type time(7) in SQL Server 2008. I solved it by changing my sql query to convert the type of time 15:00:00 to 3:00PM:
 
 SELECT ID,SUBSTRING(CAST(CAST(MyHour AS DATETIME) AS VARCHAR),13,7) AS MyHour FROM MyTable
 
 I hope this post can help you.
Tags
Input
Asked by
Travis
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Sean P. Jaeger
Top achievements
Rank 2
Oscar
Top achievements
Rank 1
Share this question
or