Click here to Skip to main content
16,020,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 15-Jan-20 18:45pm

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:

VB.NET
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
 
Share this answer
 
VB
hi

check ur field value like this

If textbox1.text is DBNull.Value then
   textbox1.text = 0 
End If
 
Share this answer
 

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


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