I found a way to get this done: (not sure if there are better ways to do this, if so please do tell)
First create a new DataSet with same columns (.Copy) as the original but remove the rows (.Clear)
DataSet dsInvoiceDataFiltered = new DataSet();
DataTable dtInvoiceDataFiltered = dsInvoiceData.Tables[0].Copy();
dtInvoiceDataFiltered.Clear();
Second create a DataTable to hold the LOGUID entries in dtInvoiceDataFiltered where VALUE !=0
DataTable dtDistinctActivityPerLogUid = new DataTable("DistinctActivityPerLogUid");
dtDistinctActivityPerLogUid.Columns.Add(new DataColumn("Activity", typeof(string)));
dtDistinctActivityPerLogUid.Columns.Add(new DataColumn("Loguid", typeof(int)));
Then apply filter logic on the original DataSet
foreach (DataRow dr in dsInvoiceData.Tables[0].Rows)
{
int iVALUE = Convert.ToInt32(dr["VALUE"]);
int iLogUid = Convert.ToInt32(dr["LOGUID"]);
string sActivity = Convert.ToString(dr["ACTIVITY"]);
// This is a unique situation (MOVE)
// and must be added to the new dataset
if (VALUE == 0)
{
dtInvoiceDataFiltered.ImportRow(dr);
}
else
{
// This is a STORE/OTHER LOGUID with multiple VALUES
// only 1 of them should be added to the new list
// Check if there is already a VALUE != 0 for that LOGUID
DataRow[] drRowsThatMatchLogUID = dtDistinctActivityPerLogUid.Select("Loguid = '" + iLogUid + "' AND Activity = '" + sActivity + "' ");
if (drRowsThatMatchLogUID.Length == 0)
{
// If there isn't one in yet, add 1 to the new list
// and to the Datatable to keep track of LOGUID entries
dtInvoiceDataFiltered.ImportRow(dr);
DataRow drNewLogUID = dtDistinctActivityPerLogUid.NewRow();
drNewLogUID["Activity"] = sActivity;
drNewLogUID["Loguid"] = iLogUid;
dtDistinctActivityPerLogUid.Rows.Add(drNewLogUID);
}
}
}
// dsInvoiceDataFiltered is now the DataSet that contains the filtered solution
dsInvoiceDataFiltered.Tables.Add(dtInvoiceDataFiltered);
PS:Not using linq since I have to work in .Net 2.0