Friday, July 31, 2009

Specified cast is not valid?

I got following when I run my C# application


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 292:


Line 293: //Clear the parameters


Line 294: long PersonId = (long)cmd.Parameters["@newpersonid"].Val...


Line 295: long ClaimId = (long)cmd.Parameters["@newclaimid"].Valu...


Line 296: //string PersonId = "" + cmd.Parameters["@newpersonid"].Value;











Source File: C:\InhDSS\SQLSERVERDAL\OCF23.cs Line: 294





Stack Trace:





[InvalidCastException: Specified cast is not valid.]


INH.SQLSERVERDAL.OCF23.PersonclaimInfoIn... personclaiminfo) in C:\InhDSS\SQLSERVERDAL\OCF23.cs:294


INH.BLL.OCF23.PersonclaimInfoInsert(Pers

Specified cast is not valid?
you can try this...





change your (long)cmd.Paramet...yadada





to Convert.ToInt64(cmd.Param..);


(a long is a 64 bit int)








this usually works better than casting....and make sure the things that you want to convert are something that can be converted into a long.


No comments:

Post a Comment