Column does not allow nulls when saving

J

John

Hi

I have a vb.net winform data app with sql server 2005 backend. The ID field
in the tblClients table is an 'int' identity column that does not allow
nulls. The problem is that when I try to save the record using the below
code;

Me.Validate()
Me.CompaniesBindingSource.EndEdit()
Me.CompanyTableAdapter.Update(Me.EMSDataSet.tblClients)

I get an 'Column 'ID' does not allow nulls' error on the second line
(EndEdit()). The first few lines of stack trace is below. What is the
problem and how can I fix it?

Thanks

Regards

----------------

Stack Trace

System.Data.NoNullAllowedException was unhandled
Message="Column 'ID' does not allow nulls."
Source="System.Data"
StackTrace:
at System.Data.DataColumn.CheckNullable(DataRow row)
at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)
 
S

Steve

Hi

I have a vb.net winform data app with sql server 2005 backend. The ID field
in the tblClients table is an 'int' identity column that does not allow
nulls. The problem is that when I try to save the record using the below
code;

Me.Validate()
Me.CompaniesBindingSource.EndEdit()
Me.CompanyTableAdapter.Update(Me.EMSDataSet.tblClients)

I get an 'Column 'ID' does not allow nulls' error on the second line
(EndEdit()). The first few lines of stack trace is below. What is the
problem and how can I fix it?

Thanks

Regards

----------------

Stack Trace

System.Data.NoNullAllowedException was unhandled
Message="Column 'ID' does not allow nulls."
Source="System.Data"
StackTrace:
at System.Data.DataColumn.CheckNullable(DataRow row)
at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)

Is your code trying to insert NULL into the identity column?
 
J

John

I designed the app visually by dragging tables and controls over dataset and
forms. I would have thought the auto generated code would have taken care of
it. Where can I check? Sorry for being dumb. While configuring data adapter
I did choose stored procedures instead of sql.

Thanks

Regards
 
E

Erland Sommarskog

John said:
I designed the app visually by dragging tables and controls over dataset
and forms. I would have thought the auto generated code would have taken
care of it. Where can I check? Sorry for being dumb. While configuring
data adapter I did choose stored procedures instead of sql.

You are dragging and dropping instead of writing real code, and then you
ask why it doesn't work? :)

Since I'm coming from the SQL Server side of things, my suggestion would
be to use the Profiler to see what is actually being sent to SQL Server.
Since you selected to use stored procedures, you should be able to find
those procedures somewhere. I don't exactly what that dragging and
dropping performs, but it should result in code that is available in
your project.

--
Erland Sommarskog, SQL Server MVP, (e-mail address removed)

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
 
R

RobinS

First, remove the UPDATE and see if it's really EndEdit causing the
problems, or if it's the Update command.

If it's EndEdit, look at your dataset in the dataset designer and click on
the primary key (autonumber) field. Make sure it's set to autoincrement,
and the seed fields are -1 (autoincrementseed and autoincrementstep).

Robin S.
-----------------------------
 
C

Cor Ligthert [MVP]

John,

The change that it is in the identy column is very small, it does not matter
at all what is in that column at an insert. So have a look at the other
columns.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top