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.

Re: VS 2005 datatable.copy NoNullAllowedException by Chris

Chris
Tue Nov 28 17:57:32 CST 2006

What type is the field?

"MikeS" <MikeS@discussions.microsoft.com> wrote in message
news:6DD92644-5AEC-497B-828D-C5DC8E5C2671@microsoft.com...
>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.



Re: VS 2005 datatable.copy NoNullAllowedException by Cor

Cor
Tue Nov 28 22:34:15 CST 2006

Mikes,

Is this about strongly typed datasets?

Than try to copy the base.

Cor

"MikeS" <MikeS@discussions.microsoft.com> schreef in bericht
news:6DD92644-5AEC-497B-828D-C5DC8E5C2671@microsoft.com...
>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.



Re: VS 2005 datatable.copy NoNullAllowedException by Cor

Cor
Fri Dec 01 23:00:05 CST 2006

Mike,

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

Cor

"MikeS" <MikeS@discussions.microsoft.com> schreef in bericht
news:E306CF5D-FD90-4501-835A-39861D8D529E@microsoft.com...
>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[i] = dr[i];
> }
>
> drNew["NewColumn"] = "Some Value";
> dtUpdated.Rows.InsertAt(drNew, 0);
> }
>
> DataSet dsReturn = new DataSet();
> dsReturn.Tables.Add(dtUpdated.Copy());
>
> return dsReturn;
> }
>
> "Cor Ligthert [MVP]" wrote:
>
>> Mikes,
>>
>> Is this about strongly typed datasets?
>>
>> Than try to copy the base.
>>
>> Cor
>>
>> "MikeS" <MikeS@discussions.microsoft.com> schreef in bericht
>> news:6DD92644-5AEC-497B-828D-C5DC8E5C2671@microsoft.com...
>> >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.
>>
>>
>>