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

Reg- Invalid Cast Exception

3 Answers 114 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sugu
Top achievements
Rank 1
Sugu asked on 22 May 2007, 11:23 AM

Hi ,

The following code throws Invalid Type Cast Exception because, I am not able to convert Decimal data into Date time data.

Please send me any possible way to do this at the earliest.

DateTime et = new DateTime();

DateTime st = new DateTime();

st = Convert.ToDateTime(nstarthrs.Value);

et = Convert.ToDateTime(nendhrs.Value);

Where nstarthrs is a numeric and nendhrs are Updown Conrol holds Decimal values.

By
RSugumar

3 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 22 May 2007, 11:33 AM
Hello Sugu,

Could you please elaborate a bit on which control you refer to? And is it for WinForms and ASP.NET?

All the best,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sugu
Top achievements
Rank 1
answered on 22 May 2007, 11:40 AM
Hi Paul,
This is for Numeric Up down control values( nstarthrs , nsendhrs) in Windows application.

By
Sugu
0
Peter
Telerik team
answered on 22 May 2007, 05:08 PM
Hi Sugu,

Your post was moved to the WinForms Forum section, as your question is not related to DNN development.

Your idea to cast directly decimal/numeric value to DateTime without context is not very good (btw, what is this value - hour, year, ...?). If the values of up/down controls are hours, try to convert numeric value using Datetime constructor instead of Convert.ToDateTime:

DateTime et=new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, (int)nstarthrs.Value, DateTime.Now.Minute, DateTime.Now.Second );
 
DateTime st=new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, (int)nendhrs.Value, DateTime.Now.Minute, DateTime.Now.Second );



On a side note, we will have to make a small disclaimer here - since your question is not directly related to our Winforms controls, we may not be in the position to help you out further. You can try Microsoft's www.windowsclient.net if you have similar questions in the future.

Good luck!
 
 
Greetings,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Sugu
Top achievements
Rank 1
Answers by
Paul
Telerik team
Sugu
Top achievements
Rank 1
Peter
Telerik team
Share this question
or