Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi am using dynamic in my project and am getting error which i mentioned above.

C#
if((Offset + BUFFER_LENGTH) >= System.Convert.ToInt32(LengthOutParam.Value))//this line am getting error

                   SizeParam.Value = System.Convert.ToInt32(LengthOutParam.Value) - Offset;
               else SizeParam.Value = BUFFER_LENGTH;

can any one suggest me.how to solve this error.??
thanks
Posted

Error as such is quite self explanatory. Still, if needed, a simple Google search[^] would have suggested you to check for the DBNULL validation before using it.

Try:
C#
if (LengthOutParam.Value != DBNull.Value)
{
   if((Offset + BUFFER_LENGTH) >= System.Convert.ToInt32(LengthOutParam.Value))
             SizeParam.Value = System.Convert.ToInt32(LengthOutParam.Value) - Offset;
   else SizeParam.Value = BUFFER_LENGTH;
}
 
Share this answer
 
Comments
VJ Reddy 5-Jun-12 3:34am    
Good answer. 5!
Sandeep Mewara 5-Jun-12 4:39am    
Thanks VJ.
Abhinav S 5-Jun-12 3:35am    
My 5. My point exactly.
Sandeep Mewara 5-Jun-12 4:39am    
Thanks Abhinav.
ythisbug 5-Jun-12 4:34am    
thanks sandeep
You are converting a DBnull type to an interger .
Simply check if Value is not DBNull and if not, convert to integer.

Example -
if((Offset + BUFFER_LENGTH) >= (LengthOutParam.Value == DbNull)?0:System.Convert.ToInt32(LengthOutParam.Value))
 
Share this answer
 
Comments
VJ Reddy 5-Jun-12 3:34am    
Good answer. 5!
Abhinav S 5-Jun-12 3:34am    
Thanks VJ.
Sandeep Mewara 5-Jun-12 4:39am    
Yep! 5.
Abhinav S 5-Jun-12 5:34am    
Thank you Sandeep.
Espen Harlinn 5-Jun-12 8:13am    
5'ed!
I assume that LengthOutParam is output parameter from database.

You are getting this error because in your sp this parameter hasn't been assigned a value.

And the default value is DBNull.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900