convert null to dbnull


I have a form which has object, string and numbers.

I need a function to pass values of these to return DBNULL if value is null else return the value as is. Looking for a single function to handle all this

Any help ?
Who is Participating?
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
numbers cannot be null unless its Nullable like Nullable(Of Integer) and so on.
for object and string u can check if null and return DBNull.
    Private Function Validate(val As Object) As Object
        If val Is Nothing Then
            Return System.DBNull.Value
        End If
        Return val
    End Function

Open in new window

Shahan AyyubSenior Software Engineer - iOSCommented:

Something like this would help you:

Public Function IsNull(obj As Object) As object
	Return IIF(obj.Equals(Nothing), DBNull.Value, obj)
End Function

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.