VB.net Coding Problem

Posted on 2011-10-11
Medium Priority
Last Modified: 2012-05-12
I have this set of VB code which fails if there is no data retrieved for a record in SQL.  It calls an:

Object reference not set to an instance of an object.  

The data(0) is an array and it works fine if their is data, but throws the error if the data is blank.  How can I wrap an is nothing clause around this code to prevent errors from throwing if the data array is nothing.

            Dim Cube_height As Exact.Web.UI.Controls.InputField
            Cube_height = BuildFields.BuildInputField("CSItemscube_height", False, Data(0), "", False)
Question by:red_75116
  • 2
LVL 38

Expert Comment

by:Tom Beck
ID: 36950447
You could try wrapping it in an IsDBNull conditional.

If Not IsDBNull(Data(0)) Then


End If

LVL 38

Accepted Solution

Tom Beck earned 2000 total points
ID: 36950798
The other possibility is that if the array has been initialized but not being populated with data then you could check this way:

If Not Data Is Nothing Then

'''do something with the data

End If

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

850 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