L
LunchBox
I'm getting null values in a DataSet which is pulling its data from a web
service. The nulls are creating 'System.Data.ConstraintException' in the
fields that do not allow columns. I've tried finding the reason for the
nulls, but I'm out of time. I need to erase the rows with nulls from the
dataset. Here is what I have so far, and although it throws an Invalid
Operation exception, it does delete the row with the null. But obviously I
don't want to just leave it throwing exceptions. Is there a better way to
do this?
Here's my code:
try
{
DataTable dt = Dataset1.Data;
if(Dataset1.Data.HasErrors)
{
foreach(DataRow dr in dt.Rows)
{
if(dr.IsNull("ID"))
dr.Delete();
}
Dataset1.Clear();
Dataset1.Merge(dt);
}
}
catch(Exception e){MessageBox.Show(e.GetBaseException().ToString());}
Thanks.
service. The nulls are creating 'System.Data.ConstraintException' in the
fields that do not allow columns. I've tried finding the reason for the
nulls, but I'm out of time. I need to erase the rows with nulls from the
dataset. Here is what I have so far, and although it throws an Invalid
Operation exception, it does delete the row with the null. But obviously I
don't want to just leave it throwing exceptions. Is there a better way to
do this?
Here's my code:
try
{
DataTable dt = Dataset1.Data;
if(Dataset1.Data.HasErrors)
{
foreach(DataRow dr in dt.Rows)
{
if(dr.IsNull("ID"))
dr.Delete();
}
Dataset1.Clear();
Dataset1.Merge(dt);
}
}
catch(Exception e){MessageBox.Show(e.GetBaseException().ToString());}
Thanks.