469,628 Members | 1,143 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

Column does not allow nulls when saving

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.tblCli ents)

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(DataRowChan geEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)
Mar 3 '07 #1
5 11989
On Mar 3, 10:05 am, "John" <J...@nospam.infovis.co.ukwrote:
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.tblCli ents)

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(DataRowChan geEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)
Is your code trying to insert NULL into the identity column?

Mar 3 '07 #2
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

"Steve" <mo********@hotmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
On Mar 3, 10:05 am, "John" <J...@nospam.infovis.co.ukwrote:
>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.tblCl ients)

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(DataRowChan geEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)

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

Mar 3 '07 #3
John (Jo**@nospam.infovis.co.uk) writes:
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, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Mar 3 '07 #4
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.
-----------------------------
"John" <Jo**@nospam.infovis.co.ukwrote in message
news:Oo**************@TK2MSFTNGP02.phx.gbl...
>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

"Steve" <mo********@hotmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
>On Mar 3, 10:05 am, "John" <J...@nospam.infovis.co.ukwrote:
>>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.tblC lients)

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(DataRowChan geEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)

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


Mar 4 '07 #5
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

"John" <Jo**@nospam.infovis.co.ukschreef in bericht
news:Oo**************@TK2MSFTNGP02.phx.gbl...
>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

"Steve" <mo********@hotmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
>On Mar 3, 10:05 am, "John" <J...@nospam.infovis.co.ukwrote:
>>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.tblC lients)

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(DataRowChan geEventArgs
args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)

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


Mar 4 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Joao Santa Barbara | last post: by
5 posts views Thread by Robert Stearns | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.