VS 2005 datatable.copy NoNullAllowedException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am getting a NoNullAllowedException when I try to add a datatable to a
dataset by using dataset.tables.add(datatableOld.copy()). I checked the
AllowDBNull property on the column of datatableOld that was throwing the
exception and it is set to "true". I am not sure why I am getting this
exception since a null is allowed in this column and i thought a copy copied
the schema and data. Any help with this would be appreciated.
 
Mike,

Did you already try it while giving your new table another name?

Cor

MikeS said:
I have included an example. I clone a datatable which has the AllowDBNull
set to false on the column the is causing the exception. I then add a
column
to the new table and set all the AllowDBNull property on all the columns
to
allow nulls. I then copy a some of the values from the cloned table and
add
the value to the new column. I receive the exception when the
dsReturn.Tables.Add(dtUpdated.Copy()); is executed.

private DataSet FormatTable(DataSet ds)
{
DataTable dtUpdated = ds.Tables["OldTable"].Clone();
dtUpdated.Columns.Add("NewColumn");

foreach (DataColumn col in dtUpdated.Columns)
{
col.AllowDBNull = true;
}

foreach (DataRow dr in dtCopy.Rows)
{
DataRow drNew = dtUpdated.NewRow();

for (int i = 0; i < 6; i++)
{
drNew = dr;
}

drNew["NewColumn"] = "Some Value";
dtUpdated.Rows.InsertAt(drNew, 0);
}

DataSet dsReturn = new DataSet();
dsReturn.Tables.Add(dtUpdated.Copy());

return dsReturn;
}

Cor Ligthert said:
Mikes,

Is this about strongly typed datasets?

Than try to copy the base.

Cor
 
Back
Top