Solved

Syntax Problem Using IsNull

Posted on 2006-06-13
4
240 Views
Last Modified: 2010-04-30
Hi,

I'm trying to handle null values in a field that are causing the following error:
     Cast from type 'DBNull' to type 'String' is not valid

I've tried variations on this:
     Me.txtTextBox.Text = IIF(IsNull(dr("FieldName")),"",dr("FieldName"))

But get build errors stating that IsNull is not declared.

How do I check for nulls?

(VB.Net 2003, SQL Server back end)

Thanks!


0
Comment
Question by:mbizup
[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
4 Comments
 
LVL 3

Accepted Solution

by:
fullcontact earned 250 total points
ID: 16895324
Tried something like this?

Me.txtTextBox.Text = "" & dr("FieldName")
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 16895379
Hi Miriam

You can simulate the Access Nz function by having the below in a separate code module

Public Function Nz(vValue as Variant, vValueIfNull as Variant) as

If IsNull(vValue) then
   if IsNull(vValueIfNull) then
      Nz = 0
   else
      Nz = vValueIfNull
   end if
else
   Nz = vValue
end if

End Function

0
 
LVL 61

Author Comment

by:mbizup
ID: 16895384
Hi FullContact,

That works like a charm and uses a lot fewer words!

Thanks a bunch!
0
 
LVL 61

Author Comment

by:mbizup
ID: 16895407
Jim,
Missed your post.  Thanks for the reply too.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 41
How to debug this code 7 65
VB6 common control 6 sp6 object library not registerd 3 47
Collapse and expand table in Word 2010 2 103
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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