Solved

URGENT: Printing error when printing a empty field.

Posted on 2006-07-04
7
179 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
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 500 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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now