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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:15:59+00:00 2026-06-10T07:15:59+00:00

I have an identity column in the DB which is primary key and increments

  • 0

I have an identity column in the DB which is primary key and increments its value by itself. But I have a insert query in asp.net ado.net class like below:

cmd = new SqlCommand("insert into Images(Name,[Image]) VALUES ('Nature',@img)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = TextBox1.Text;
cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;
cmd.ExecuteNonQuery();

However, it throws me exception that it cannot be null.

My idea/goal is, I just want to insert the above two values only and the primary key column should increment by itself internally in DB. I have configured that in DB. However I don’t know how to handle this error or tweak this code. Please help

  • 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-10T07:16:01+00:00Added an answer on June 10, 2026 at 7:16 am

    Make sure the ID column on your Images table is an identity column.

    For example:

    CREATE TABLE Images(
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [Name] [varchar](100) NOT NULL,
        [Image] [image] NOT NULL)
    

    If it is, then step through your code and make sure the parameters you are using are not null; TextBox1.Text and img.

    Lastly, make sure there are no other non-nullable columns on the table.

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

Sidebar

Related Questions

I have many tables; each has a primary key which is an Identity column
If I have ID column, which is a primary key and Identity is set
So I have a table with an identity column as the primary key, so
I have a table Administrator with only one column, adminId which is the primary-key.
OK, I have a table with no natural key, only an integer identity column
I have a non-nullable database column which has a default value set. When inserting
I'm using LINQ, but my database tables do not have an IDENTITY column (although
I have a database table with the primary column defined as: ID bigint identity
I have an invoice table that has InvoiceID (int identity ) Primary key. and
I just noticed that if I have an identity column in a table, when

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.