Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

NoNullAllowedException error when inserting data to a datagridview despite identity column is set to be auto-incremented

Ask Question

I have put a DataGridView in my program such that this DataGridView is corresponding to a dataset of one table and this table has a auto-incremented identity column(also,this column is set to be primary key).

This identity column is not visible in DataGridView and when a user fills other cells and clicks "save", NoNullAllowedException occurs.

Why?I want to allow user to just insert data(not another modification)

How can I do?I use C# and SQL server 2008

Cheers

Fine for the primary key, but what about the others? In theory this exception is raised when you submit nulls in a Not Null field. Are you trying to submit nulls there? MPelletier Jul 30, 2010 at 13:41

Look at your table and find all the columns that are NOT NULL and make sure the form is posting something into those fields.

If it really is just the Primary Key that's causing the issue verify that it works by posting data directly from SQL server management studio with T-SQL Code (INSERT INTO) etc.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .