Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,


I am unable to Filter The DataTable.


Here is what i have tried
Note: I am using .net 1.1 version


C#
DataTable dtTableInput = new DataTable();
            dtTableInput = GetDataTable();
            DataSet dsFinal = new DataSet();
            DataTable dtServcice = new DataTable();
            for (int i = 0; i <= dtDistinctValues.Rows.Count - 1; i++)
            {

                DataView dv = dtTableInput .DefaultView;
                dv.RowFilter = "Service = 'ABC'";
                dtServcice =dv.Table.Copy();
                dtServcice.TableName=dtDistinctValues.Rows[i][0].ToString();
                dsFinal.Tables.Add(dv.Table);
            }
Posted
Updated 17-Sep-14 19:34pm
v3
Comments
George Jonsson 18-Sep-14 1:09am    
Not sure what you are trying to do here, but you should try to apply the filter on the DataTable instead of the DataSet.
dtServcice.DefaultView.RowFilter = "Service = 'ABC'";
Prasad Avunoori 18-Sep-14 1:52am    
I am sorry for the typo that was DataTable only . I just updated the Question.
Sinisa Hajnal 18-Sep-14 2:23am    
By not able to filter you mean you get all rows into dtServcice instead of those from the filter?

Bt you're copying whole table dv.Table.Copy...you should iterate through dataview and add its rows to dtServcice...you also don't have to call New DataTable on dtInput since you're filling it with GetDataTable...not an error just inefficient.
Prasad Avunoori 18-Sep-14 2:38am    
Cann't i achieve it without iteration?
Sinisa Hajnal 18-Sep-14 2:43am    
Sure. Use .NET 2.0 or newer and use view.ToTable(true, ..column names...) - in 1.1 you have to iterate.

Where true means distinct and list of column names is either string or stringarray (not sure, no code open in front of me)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900