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: Object cannot be cast from DBNull to other types.
As you already now that there is some issue with your data that raise casting issue, why not you have a public method in your code behind and you pass parameters from UI to method , its easy to debug that function in Cb and you can have try catch block over
there, you can do more..
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
399 Points
1101 Posts
Object cannot be cast from DBNull to other types
Mar 25, 2017 04:06 AM|asp.ambur|LINK
Hello
This is my code
How to avoid this below from the above code
Object cannot be cast from DBNull to other types.
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: Object cannot be cast from DBNull to other types.
All-Star
52493 Points
15665 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 04:38 AM|oned_gk|LINK
This because the data is null, the trick is ensure the result always has value
Suwandi - Non Graduate Programmer
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 04:49 AM|asp.ambur|LINK
Can it be possible to do in aspx page in this below code
All-Star
52493 Points
15665 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 07:01 AM|oned_gk|LINK
vb
c#
vb
Suwandi - Non Graduate Programmer
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 10:37 AM|asp.ambur|LINK
I'm using asp.net 2.0 C#
getting error
Syntax error, ':' expected
All-Star
52493 Points
15665 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 10:40 AM|oned_gk|LINK
i mean
Suwandi - Non Graduate Programmer
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 10:48 AM|asp.ambur|LINK
Still the same error
Object cannot be cast from DBNull to other types.
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 10:51 AM|asp.ambur|LINK
This is my code for Multiply
Your Code Please
Contributor
2096 Points
1040 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 11:57 AM|Khuram.Shahzad|LINK
As you already now that there is some issue with your data that raise casting issue, why not you have a public method in your code behind and you pass parameters from UI to method , its easy to debug that function in Cb and you can have try catch block over there, you can do more..
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 12:07 PM|asp.ambur|LINK
any other way to do it in rowdatabound.. to avoid this error
Contributor
5290 Points
2307 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 01:53 PM|AngelinaJolie|LINK
Hi asp.ambur,
Please refer to code below:
please have a try.
Best regards,
Jolie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
All-Star
52493 Points
15665 Posts
Re: Object cannot be cast from DBNull to other types
Mar 25, 2017 03:36 PM|oned_gk|LINK
Suwandi - Non Graduate Programmer
Member
399 Points
1101 Posts
Re: Object cannot be cast from DBNull to other types
Mar 26, 2017 07:53 AM|asp.ambur|LINK
Again same error
Object cannot be cast from DBNull to other types.
All-Star
31362 Points
7055 Posts
Re: Object cannot be cast from DBNull to other types
Mar 27, 2017 10:40 AM|kaushalparik27|LINK
[KaushaL] Blog Twitter [MS MVP 2008 & 2009] [MCC 2011] [MVP Reconnect 2017]
Don't forget to click "Mark as Answer" on the post that helped you