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 8776735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:07:32+00:00 2026-06-13T19:07:32+00:00

I have a null value in my database which gives me an error if

  • 0

I have a null value in my database which gives me an error if I try perform any mathematical operations on it. I tried putting this in my controller action:

If String.IsNullOrEmpty(item.Tbl_Food.Fiber_TD_g) Then
            item.Tbl_Food.Fiber_TD_g = 0
End If

This my model for the field:

Public Property Fiber_TD_g() As Nullable(Of Double)

However, it says “Nullable object must have a value.” on the If String.IsNullOrEmpty(item.Tbl_Food.Fiber_TD_g) Then line. How can I check if the “string” (it’s a double, not a string) is empty and default it to zero, properly?

Edit:

I tried a suggestion below, and I no longer get an error in my controller, but instead in my View. It says, “Nullable object must have a value.” on the line FiberTotal += item.Tbl_Food.Fiber_TD_g in my view.

Dim food = db.Tbl_Food_Logs.Where(Function(x) x.FLog_Employee_ID = empId And x.FLog_Created_Date >= date2 And x.FLog_Created_Date < tomorrow)

For Each item In food

    If IsDBNull(item.Tbl_Food.Fiber_TD_g) Then
        item.Tbl_Food.Fiber_TD_g = 0
    End If

Next
Return View(food)
  • 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-06-13T19:07:34+00:00Added an answer on June 13, 2026 at 7:07 pm

    As its name implies, String.IsNullOrEmpty is a string operation. It won’t work if you pass a double. Instead check to see if it Is Nothing:

    If item.Tbl_Food.Fiber_TD_g Is Nothing Then
                item.Tbl_Food.Fiber_TD_g = 0
    End If
    

    This operation is common enough that VB has a shortcut, called the null coalescing operator (2-argument If):

    item.Tbl_Food.Fiber_TD_g = If(item.Tbl_Food.Fiber_TD_g, 0)
    

    When If has two arguments, it returns the first argument if it’s not null and the second if it is.

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

Sidebar

Related Questions

I have a text value in my AR model which defaults to null. I
I have the following simple function: private void EnableDisable941ScheduleBButton() { if (this._uosDepositorFrequency.Value != null)
I have a non-nullable database column which has a default value set. When inserting
i have the following program which goes to database and gets the value, i
I have integer type field in database which is having property Not Null. when
so in my database some rows have NULL values, and when I select *
i am trying to execute the records that have TotalTime null value from the
I have a table with 42 million records. 32 million have a null value
I'm trying to count the number of records that have a null DateTime value.
I have to add a column whose default value is not null by default

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.