Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7168073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:42:21+00:00 2026-05-28T14:42:21+00:00

In my ASP.Net Web-Application, I’m getting this error: Conversion from type ‘DBNull’ to type

  • 0

In my ASP.Net Web-Application, I’m getting this error:

Conversion from type ‘DBNull’ to type ‘Boolean’ is not valid.

From this function:

Namespace atc
    Public Class Nil
        '...
        Public Shared Function Bool(ByVal Item As Object) As Boolean
            Return IIf(Item IsNot Nothing AndAlso Not IsDBNull(Item), CBool(Item), False)
        End Function
        '...
    End Class
End Namespace

As you can see, I’m explicitly checking if Item is DBNull, and if it is then I return False.

The error does not occur when Item is not DBNull, so I don’t understand why this is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:42:22+00:00Added an answer on May 28, 2026 at 2:42 pm

    When using IIf then all arguments get evaluated, no matter if the condition evaluates to true or false. In your case the function will return false if Item is null or DBNull, but CBool(Item) will be silently executed in the background anyway and therefore throws an exception.

    In VB.NET 2008 the If keyword was added to provide a real ternary operator. Replace your IIf function call with the following:

    Public Shared Function Bool(ByVal Item As Object) As Boolean
        Return If(Item IsNot Nothing AndAlso Not IsDBNull(Item), CBool(Item), False)
    End Function
    

    Excerpt from MSDN:

    An IIf function always evaluates all three of its arguments, whereas
    an If operator that has three arguments evaluates only two of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My ASP.net web application is getting a request from another application with a querystring
My asp.net web application is reading and decrypting the password from a XML file
So I have an asp.net Web Application (Not Web Site) that I am trying
I am using an ASP.NET Web Application , I want to change this application
I'm creating an ASP.NET web application to schedule tasks on our server from a
We have an ASP.NET web application which uses ASP.NET Ajax. We open it from
Is a asp.net web application (hosted in IIS) considered a process? And this process
In asp.net Web application, i write code for datalist paging like this : PagDat
I have an asp.net web application. The application reads data from an xml. The
I need my ASP.NET web application to use silverlight controls in my web page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.