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

  • Home
  • SEARCH
  • 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 7856675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:47:11+00:00 2026-06-02T20:47:11+00:00

Can anyone explain why I’m sometimes gets a NULL exception on this insert method?

  • 0

Can anyone explain why I’m sometimes gets a NULL exception on this insert method?
As said is only sometimes, which for me is just even more confusing.

The table OrderLine has a referemce to the table Product in the datacontext (.dbml file)

public void insertNewOrder(string accountNumber, int orderId)
{
    var order = orderRep.GetOrderById(orderId);
    var orderlineData = orderLineRep.GetOrderLines(order.OrderID);

    foreach (var orderLine in orderlineData)
    {
        int currentStatus = dlvRep.getAxOrderStatusNumber(orderLine.ItemNumber, 0);
        string levering = "";
        string status = dlvRep.getAxOrderStatus(orderLine.ItemNumber, currentStatus, out levering);
        WebsiteOrderStatus insertNew = new WebsiteOrderStatus
        {
                AccountNumber = accountNumber,
                OrderID = orderId,
                ItemNumber = orderLine.ItemNumber,
                ItemName = orderLine.Product.Name,
                FormatName = orderLine.Product.ProductFormatName,
                Quantity = orderLine.Quantity,
                Price = orderLine.Price,
                Status = status,
                Levering = levering,
                LastUpdatedStatus = currentStatus,
                CreatedDate = DateTime.Now
        };
        db.WebsiteOrderStatus.InsertOnSubmit(insertNew);
        db.SubmitChanges();
    }
}

Exception message:

Cannot insert the value NULL into column 'FormatName', table 'GWportal.dbo.WebsiteOrderStatus'; column does not allow nulls. INSERT fails.

The statement has been terminated.

When I look up the products which this code is having trouble finding the ProductFormatName for. The value of ProductFormatName is not NULL and it’s having the value as I expected ex: “PS3”.

Another strange thing is, why aren’t it complaining about:

ItemName = orderLine.Product.Name,

This coulmn does not allow nulls either.

  • 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-02T20:47:13+00:00Added an answer on June 2, 2026 at 8:47 pm

    It’s probably a bug in the code fororderLineRep.GetOrderLines(order.OrderID) that causes orderLine.Product.ProductFormatName to be set to null.

    Try adding some debug code:

        foreach (var orderLine in orderlineData)
        {
            if (orderLine.Product.ProductFormatName == null) {
                throw new Exception("ProductFormatName == null");
            }
    
            // ...
    

    Another strange thing is, why aren’t it complaining about:

    ItemName = orderLine.Product.Name,
    

    This coulmn does not allow nulls either.

    I can think of two explanations:

    1. orderLine.Product.Name isn’t null. The bug mentioned above may affect only ProductFormatName.
    2. orderLine.Product.Name is null, but one error is enough to terminate the statement immediately. Only one error will be reported. Other errors that are also present won’t be reported until the first error is fixed.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain a parse error like this one: Method 'get_EnableCdn' in type 'System.Web.UI.ScriptManager'
Can anyone explain what this mod_rewrite rule is doing? I'm trying to comment the
Can anyone explain to me what this means? Run-Time Check Failure #0 - The
Can anyone explain the following immediate window behavior: Debug.Print mDb.DatabaseOptions Method arguments must be
can anyone explain me what happen here?? i have this html code: <div class=calculadora>
Can anyone explain why this happens? mybox:$ ruby script/console Loading development environment (Rails 2.3.5)
Can anyone explain the meaning of this code? if (data.result) { $('ul#intlist').append(data.content); }
Can anyone explain to me why this code below does not work? #include opencv/cv.h
Can anyone explain, why this program is returning the correct value for sqrt_min? int
Can anyone explain this to me , String str = Hello; str += ((char)97)

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.