Click here to Skip to main content
13,044,428 members (114,245 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have created a table and fields declared as int null and i used stored procedure for saving the record. while saving the record i got the this error "

Conversion from type 'DBNull' to type 'Integer' is not valid." Please help ... thanks in advnc...
Posted 15-Sep-11 23:45pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Somewhere in your saving code you compare a integer to a variable.
This variable has the dbnull value.

If this is within your stored procedure you can use the 'isnull(value,returnvalue)' method from TSQL.

If this is in your .NET code you'll have to check if the variable is dbnull (there is a function for that 'IsDBNull' that returns a boolean).
You can write your own Isnull function if you want.
Something along the lines of this:

Public Shared Function IsNull(ByVal controleValue As Object, ByVal returnValue As Object) As Object
        If IsDBNull(controleValue) Or controleValue Is Nothing Then
            Return returnValue
        Else
            Return controleValue
        End If
    End Function
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

hi
 
check ur field value like this
 
If textbox1.text is DBNull.Value then
   textbox1.text = 0 
End If
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100