Solved

convert null to dbnull

Posted on 2013-06-06
2
349 Views
Last Modified: 2013-06-07
Hi,

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 ?
0
Comment
Question by:GRChandrashekar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39225154
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

0
 
LVL 19

Expert Comment

by:Shahan Ayyub
ID: 39225649
hi!

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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question