?
Solved

URGENT: Printing error when printing a empty field.

Posted on 2006-07-04
7
Medium Priority
?
185 Views
Last Modified: 2010-04-23
Could someone please help me urgently!

I am trying to print the addresses of clients on an Access Database using VB.net.  But when one of the fields is empty I get an error.  I've tried putting


if not client("Add5") = ""
and
if not client("add5") = nothing

and cant avoid the error

any ideas?

Thanks
Bsturge
0
Comment
Question by:bsturge
[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
7 Comments
 
LVL 5

Expert Comment

by:tsay
ID: 17035917
Try checking for DBNull values.

If client("Add5") <> "" and client("Add5") <> DBNull.Value then ...

HTH
0
 
LVL 9

Accepted Solution

by:
lojk earned 2000 total points
ID: 17036006
I usually add a seperate function.. Reduces much typing time later...

        Public Shared Function CheckNullString(ByVal stringToCheck As Object) As String
                Dim tret As String = ""
                Try
                        tret = CStr(stringToCheck)
                Catch ex As Exception
'catch the error if you like...
                End Try
                Return tret
        End Function

then..

Console.writeline (checknullstring(client("Add5")))
0
 
LVL 1

Expert Comment

by:SteSi
ID: 17036248
try this:

IIf(VarType(client("Add5"))= VariantType.Null, "", client("Add5"))

This will return the value if it is not null and a blank string if it is null!
0
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.

 

Author Comment

by:bsturge
ID: 17036261

Tsay,

Thanks for your solution.  The problem is that the value is DBNull but when I put the suggested line:

If client("Add5") <> "" and client("Add5") <> DBNull.Value then ...

I get this error:

 Operator '<>' is not defined for types 'System.Object' and 'System.DBNull'. Use 'Is' operator to compare two reference types.

0
 
LVL 5

Expert Comment

by:tsay
ID: 17036272
Oh,

then try this:
If client("Add5") <> "" and client("Add5) Is Not DBNull.Value then ...
0
 
LVL 5

Expert Comment

by:tsay
ID: 17036291
Ok that's also wrong so I took the effort of actually opening Visual Studio,

it should be this:

If client("Add5") <> "" and Not client("Add5) Is DBNull.Value then ...
0
 
LVL 9

Expert Comment

by:lojk
ID: 17037162
Not only has it got to work but you have to type it over and over and over and over again...

My way keeps your inline code nice and neat... (and also allows you to refactor the CheckNullString Function Later). Just for reference i also have a CheckNullNumber function that does the same but... well get you get the idea..

Thanks for the points..
0

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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