Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 12 of 12

Thread: Cannot insert the value NULL into column 'ProductID'

  1. #1
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default Cannot insert the value NULL into column 'ProductID'

    Hello,

    I am getting this error when trying to add a new product. At first, it stated that it, "Cannot insert the value NULL into column 'Template'," so I made that to allow nulls to see if that would work. But now I am getting this error and I am not sure why.

    Any help would be GREATLY appreciated...

    Cheers,

    ~D

  2. #2
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    how are you trying to add a new product? Through a sql statement, one by one in the admin, through an import or some other way?

  3. #3
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by mmcgeachy View Post
    how are you trying to add a new product? Through a sql statement, one by one in the admin, through an import or some other way?
    I am trying to add it through the Admin/Control Panel...

  4. #4
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Does anyone have any thoughts on this? This is kind of a big deal... I cannot add new products!

  5. #5
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    Have you had any customisations done?

    Have you modified the code?

    Are you able to import a product using the spreadsheet import?

    You really don't want to have a null value in your ProductID column - I'd undo your modification that allowed this.


    TTFN

    BFG

  6. #6
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    I did not allow a null value for ProductID. I am not sure what could have caused this. I have only modified XML packages - and simple things too! Formatting, layout, etc...

  7. #7
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Here is the error:

    Code:
    Server Error in '/' Application.
    Cannot insert the value NULL into column 'ProductID', table 'DatabaseName.dbo.Product'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'ProductID', table 'DatabaseName.dbo.Product'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
    
    Source Error:
    
    
    Line 1328:
    Line 1329:                sql.Append(")");
    Line 1330:                DB.ExecuteSQL(sql.ToString());
    Line 1331:
    Line 1332:                using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
    
    
    Source File: e:\inetpub\wwwroot\Web\admin\entityEditProducts.aspx.cs    Line: 1330
    
    Stack Trace:
    
    
    [SqlException (0x80131904): Cannot insert the value NULL into column 'ProductID', table 'DatabaseName.dbo.Product'; column does not allow nulls. INSERT fails.
    The statement has been terminated.]
       AspDotNetStorefrontCore.DB.ExecuteSQL(String Sql) in C:\AspDotNetStorefront\Fortress\DP_Products\WebReleases\AspDotNetStorefrontML\Ashland\ASPDNSFCore\DB.cs:675
       AspDotNetStorefrontAdmin.entityEditProducts.UpdateProduct() in e:\inetpub\wwwroot\Web\admin\entityEditProducts.aspx.cs:1330
       AspDotNetStorefrontAdmin.entityEditProducts.btnSubmit_Click(Object sender, EventArgs e) in e:\inetpub\wwwroot\Web\admin\entityEditProducts.aspx.cs:1087
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
    
    
    Version Information: Microsoft .NET Framework Version:2.0.50727.5456; ASP.NET Version:2.0.50727.5456

  8. #8
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    It doesn't have anything to do with my .NET version, does it?

  9. #9
    Skriver is offline Senior Member
    Join Date
    Apr 2012
    Posts
    188

    Default

    That's quite an old version of .NET but should not be the issue. Looks like the INSERT command is somehow triggering that Null Value into the column when however you are adding the products occurs.

    Are you able to log into your SQL database? I would look at the product Id's that contain a NULL value and replace them with a numerical value (even if it's false) so that at least you have stability within your table. Then change this back so that Null Values are not allowed and try your upload method again (I would also back up the db)

    Something like

    SELECT * FROM Products WHERE ProductID IS NULL

    Should find them

  10. #10
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    Quote Originally Posted by Skriver View Post
    That's quite an old version of .NET but should not be the issue. Looks like the INSERT command is somehow triggering that Null Value into the column when however you are adding the products occurs.

    Are you able to log into your SQL database? I would look at the product Id's that contain a NULL value and replace them with a numerical value (even if it's false) so that at least you have stability within your table. Then change this back so that Null Values are not allowed and try your upload method again (I would also back up the db)

    Something like

    SELECT * FROM Products WHERE ProductID IS NULL

    Should find them
    I do not have any ProductIDs with a NULL value, nor a blank/empty string or a datalength of less than 1.

    Why isn't that field an identity specific field? Looking at the design of that table, it is a key, but not auto-incrementing? That's a but strange....

    I seriously have no idea why this is not working!

  11. #11
    GoVedia is offline Member
    Join Date
    Oct 2012
    Location
    Orange, CA
    Posts
    98

    Default

    Quote Originally Posted by donato View Post
    Hello,

    I am getting this error when trying to add a new product. At first, it stated that it, "Cannot insert the value NULL into column 'Template'," so I made that to allow nulls to see if that would work. But now I am getting this error and I am not sure why.

    Any help would be GREATLY appreciated...

    Cheers,

    ~D
    What exactly did you do to allow nulls?
    Robert Kanaan
    AspDotNetStorefront Development Partner
    robert@GoVedia.com
    408-758-8845

    GoVedia
    http://GoVedia.com
    Approved AspDotNetStorefront Development Partner
    AspDotNetStorefront Recommended Reseller

  12. #12
    donato is offline Senior Member
    Join Date
    Jun 2009
    Posts
    215

    Default

    My apologies...

    I figured out the problem...

    I had created new tables from our old website to the latest version. I simply did a select INTO statement. THe problem being with that, and it's a small problem to me, is that in the Design of the table(s), the Default Value or Binding does not come over. I am going over the tables now.

    Thank you so much!

    D