Can't enter int value of 0?

  • Thread starter Thread starter dsmith
  • Start date Start date
D

dsmith

Using Visual Studio Express 2008.

I've built a program that uses an SQL/CE database (v.3.5), and
constructed a strongly-typed dataset (.xsd) based on that database.
One of the fields is an Int32 value. It's set as AllowDBNull = false
(in both VS designer and database), and a default value of 0.

When I tried to enter a new record into this table and update it (call
the UpdateAll on the TableManager class once all the table adapters
have been set up) it throws an exception saying that "The column
cannot contain null values. [ Column name = //column//,Table name = //
table// ]". The datarow was created with an explicit value of 0 set
for that column.

As I understood it, 0 is not the same as DBNull, therefor this
shouldn't be happening. Am I mistaken, and that I'm required to allow
Nulls in any int column that can possibly be 0? If I allow nulls in
this column, everything seems to work ok (though I had another bug
while testing, saying that the value was null when trying to iterate a
Sum() on it, which is why I tried to change it back again).
 
As soon as you add a datarow to a datatable, then all the values which may
not be null have to be filled in advance

Cor
 
As soon as you add a datarow to a datatable, then all the values which may
not be null have to be filled in advance

Cor

Umm.. huh?

The column in question was given a value. That value was 0, as in a
literal '0' passed in as a parameter.


Anyway, finally tracked down the issue. The database/dataset
configuration was modified as I went along, but the auto-generated
Fill/Insert/Update/Delete commands didn't get updated to match the
changes to the dataset, so that particular column wasn't being sent to
the database on update. After re-generating, it appears to be working
properly.
 
Back
Top