troubleshooting Question

Help solving error: "Conversion from type 'DBNull' to type 'String' is not valid."

Avatar of cdemott33
cdemott33Flag for United States of America asked on
C#ASP.NETVisual Basic.NET
5 Comments1 Solution367 ViewsLast Modified:
Hi Folks - I am getting an error in my procedure below and I'm hoping you can help me fix the problem.  

I have BLL Function that returns a datatable.  Some of the rows returned from my datatable may not have a value, so it returns DBNull.  How can I avoid the "DNull to type 'String' error when there is no value returned?

Please see my code below.
Dim customerName As String
        Dim customerAddrOne As String
        Dim customerAddrTwo As String
        Dim customerAddrThree As String

        Dim dt As DataTable = clientLogic.GetClientInfo(ClientID)

        If dt.Rows.Count > 0 Then
            customerName = dt.Rows(0).Item("SOLDTO")
            customerAddrOne = dt.Rows(0).Item("SOLD1")
            customerAddrTwo = dt.Rows(0).Item("SOLD2")
            customerAddrThree = dt.Rows(0).Item("SOLD3")
        End If
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros