Home All Groups Group Topic Archive Search About

Deleting from typed DataSet - why DBNull error?

Author
12 Mar 2006 7:26 AM
deko
I've set up a DataTable (dtPrj) like this:

   DataTable tblProject = database.Tables.Add("TableProject");
   DataColumn project_ID = tblProject.Columns.Add("Project_ID",
typeof(Int32));
   project_ID.AllowDBNull = false;
   project_ID.Unique = true;
   project_ID.AutoIncrement = true;
   project_ID.AutoIncrementSeed = 1;
   project_ID.AutoIncrementStep = 1;
   tblProject.PrimaryKey = new DataColumn[] { tblProject.Columns[0] };
   tblProject.Columns.Add("ProjectName", typeof(string));
  [other columns...]

When I attempt to delete like this:

dtPrj = database.Tables[tblPrj];
DataRow drPrj = dtPrj.Rows.Find(definitionID); //the Project_ID
drPrj.Delete();
dtPrj.AcceptChanges();

I get this error:

System.Data.NoNullAllowedException was unhandled
  Message="Column 'Project_ID' does not allow nulls."
  Source="System.Data"

I understand that I've disallowed nulls in the pk, but I just want to delete
it - and I have other relations set to enforce cascading deletes from other
tables.

Why am I getting this error?  Should I remove the AllowDBNull = false
statement?  Why?

Thanks in advance.

AddThis Social Bookmark Button