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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:24:09+00:00 2026-06-03T02:24:09+00:00

I have a table A with an Identity column. When I insert a row

  • 0

I have a table A with an Identity column.
When I insert a row via visualStudio it failed in the SubmitChanges with the following error:

InvalidOperationException: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type

I searched about this in google and I found some discussions about the same issue. one of them is Here.
it says that it’s because the procedure returns a null value.
I did as is wrote there. used sql trace, copy the insert command and run it in sql server.
it realy returns null but the row was inserted correctly!!!
the command as it is in the sql trace:

exec sp_executesql N'INSERT INTO [dbo].[MyName_Tbl]([x], [y], [z], [c], [v], [b], [n], [m], [a], [s], [d], [f], [g], [h], [j], [k], [l], [q], [w], [e], [r])
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15, @p16, @p17, @p18, @p19, @p20)

SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]',N'@p0 varchar(8000),@p1 varchar(8000),@p2 nvarchar(4000),@p3 nvarchar(4000),@p4 varchar(8000),@p5 nvarchar(4000),@p6 varchar(8000),@p7 varchar(8000),@p8 nvarchar(4000),@p9 nvarchar(4000),@p10 nvarchar(4000),@p11 nvarchar(4000),@p12 nvarchar(4000),@p13 varchar(8000),@p14 varchar(8000),@p15 nvarchar(4000),@p16 varchar(8000),@p17 nvarchar(4000),@p18 nvarchar(4000),@p19 nvarchar(4000),@p20 decimal(5,2)',@p0='406',@p1='Kabala',@p2=N'01/05/2012 13:47:01',@p3=N'k406/00033',@p4='406/00033',@p5=N'xxx',@p6='127.0.0.1',@p7='10',@p8=N'yyy',@p9=N'hh hh',@p10=N'0527159080',@p11=N'',@p12=N'',@p13='4580',@p14='1',@p15=N'Visa',@p16='0115',@p17=N'10',@p18=N'0',@p19=N'0232323',@p20=0

Can you explain me what’s the problem and why in sql it executed correctly and in VS I get an error?

  • 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-03T02:24:10+00:00Added an answer on June 3, 2026 at 2:24 am

    The error you are receiving has nothing to do with an invalid SQL statemt which explains why it works fine when you execute it directly on SQL Server.

    The error is being thrown on your app and it’s simply because the SQL statement is supposed to return an int containing the value of the last id inserted in the table but instead is returning a NULL value, which makes your program choke since null cannot be assigned to an int unless you declare it as a Nullable<int> (int?)

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

Sidebar

Related Questions

We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have a table with an identity column that have incremented by 1 for
So I have a table with an identity column as the primary key, so
OK, I have a table with no natural key, only an integer identity column
I just noticed that if I have an identity column in a table, when
Imagine I have these columns in a table: id int NOT NULL IDENTITY PRIMARY
I have the following table: create table ARDebitDetail(ID_ARDebitDetail int identity, ID_Hearing int, ID_AdvancedRatePlan int)
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a sql server table: CREATE TABLE [Workflow].[MilestoneDate]( [MilestoneDateId] [int] IDENTITY(1,1) NOT NULL,

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.