J
Jesper Stocholm
I have a DataSet that I need to do some sorting and filtering on.
Basically I need to filter on the value in the 3rd column being equal to
'r' and sorting in descending order on column 20.
I have seen, that I can put the DataSet (or its table) through a DataView
and apply sorting and filtering to it - like
private void CreateHtmlTable(XmlTextWriter w, DataSet reimbursementData_)
{
DataView dataView = new DataView();
dataView = reimbursementData_.Tables[0].DefaultView;
dataView.RowFilter = "Type = 'r'";
dataView.Sort = "DebtorID";
foreach (DataRow row in reimbursementData_.Tables[0].Rows)
{
// incomplete code below
int debtorId = 0;
if (debtorId != Convert.ToInt32(row[20]))
{
// write end table row definition </tr>...
}
else
{
// write start table row definition ...
}
}
}
My question is this: In the code above I loop through the rows of the
table of the original dataset - but is this correct? Will the original
dataset be affected by the sorting and filtering applied by the DataView?
If this is not the case - how do I loop through the DataView? The class
does not seem to have any methods available for this.
Thanks,
)
Basically I need to filter on the value in the 3rd column being equal to
'r' and sorting in descending order on column 20.
I have seen, that I can put the DataSet (or its table) through a DataView
and apply sorting and filtering to it - like
private void CreateHtmlTable(XmlTextWriter w, DataSet reimbursementData_)
{
DataView dataView = new DataView();
dataView = reimbursementData_.Tables[0].DefaultView;
dataView.RowFilter = "Type = 'r'";
dataView.Sort = "DebtorID";
foreach (DataRow row in reimbursementData_.Tables[0].Rows)
{
// incomplete code below
int debtorId = 0;
if (debtorId != Convert.ToInt32(row[20]))
{
// write end table row definition </tr>...
}
else
{
// write start table row definition ...
}
}
}
My question is this: In the code above I loop through the rows of the
table of the original dataset - but is this correct? Will the original
dataset be affected by the sorting and filtering applied by the DataView?
If this is not the case - how do I loop through the DataView? The class
does not seem to have any methods available for this.
Thanks,
