?
Solved

Syntax Problem Using IsNull

Posted on 2006-06-13
4
Medium Priority
?
242 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 1000 total points
ID: 16895324
Tried something like this?

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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