Remove row with null value from DataSet??

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top