Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

datareader and null values in table

Posted on 2006-11-17
2
Medium Priority
?
329 Views
Last Modified: 2010-04-23
Hey guys

Im confused once again

I have a winform that is populated by a datareader...it works ok until the table it reads has a field with a null value

while reader.read
           lblchemicalvalue.text = reader("t_checmialprice") ''.........String
           lblChemicalWeight.text = reader("t_chemicalWeight) "..........Integer

end while
everything tools along until i hit a null value in the table... ( its a very old database...no idea of how nulls got there )

do how do i handle the exceptions
Steve
 
0
Comment
Question by:stephenz43
[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 29

Accepted Solution

by:
Nightman earned 2000 total points
ID: 17969546
Try something like this:

lblchemicalvalue.text = NCheck(reader("t_checmialprice"),"").

Private Function NCheck(ByVal x As Object, ByVal yDefault As Object) As Object
    If x Is System.DBNull.Value Then
      NCheck = yDefault
    Else
      NCheck = x
    End If
  End Function

Or

lblchemicalvalue.text = IIF((reader("t_checmialprice") Is DBNull.Value),"",reader("t_checmialprice")).
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17969737
lblchemicalvalue.text = GetString(reader("t_checmialprice")) ''.........String
lblChemicalWeight.text = GetInteger(reader("t_chemicalWeight)) "..........Integer


Private Function GetString(ByVal fld As Object) As String
    If fld Is System.DBNull.Value  Then
      return ""
    Else
      return System.Convert.Tostring(fld)
    End If
End Function

Private Function GetInteger(ByVal fld As Object) As Integer
    If fld Is System.DBNull.Value  Then
      return 0
    Else
      return System.Convert.ToInteger(fld)
    End If
End Function
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

618 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