Home
> Uncategorized > Filtering a DataSet
Filtering a DataSet
I know that .NET offers a number of ways to show different filtered views of a DataSet, however, if you want to actually change the DataSet, you run into nasty little errors such as "This row already belongs to another table" or "These columns dont currently have unique values" etc.
So here’s a method I made for filtering datasets…
public
static DataSet FilterDataSet(DataSet ds,string TableName,string column, string filter){
DataSet dsCopy = ds.Copy();
ArrayList alRowsToRemove =
new ArrayList(); foreach(DataRow dr in dsCopy.Tables[TableName].Rows){
if (dr[column].ToString()!=filter){
alRowsToRemove.Add(dr);
}
}
foreach(DataRow dr in alRowsToRemove){
dsCopy.Tables[TableName].Rows.Remove(dr);
}
return dsCopy;}
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback