tags:

views:

60

answers:

2

Hi,
I have a datatable which contains all these record(see SQL query). Instead of writing a new stocked procedure. Can I filter this condition in my datatable using dataview?

If yes how to do so?

Tank you

SELECT * FROM students WHERE class='10'
AND Names IN ('kiran', 'manju', 'ram' , 'peter')AND Language = 'english'
+2  A: 

If you use the SQL in your question to create a new view, you could then run other queries against that view and have that filtering done automatically:

CREATE VIEW MYVIEW AS 
SELECT * FROM students WHERE class='10'
  AND Names IN ('kiran', 'manju', 'ram' , 'peter')
  AND Language = 'english'
kdmurray
@kdmuray: he was talking about stocked procedure, so I suppose the view solution is not what he is looking for, I think he want client filtering
RageZ
+1  A: 

There is a nice article how to filter data using dataview there.

you would have to play with the RowFilter property of the Dataview.

private void MakeDataView() 
{
    DataView view = new DataView();

    view.Table = DataSet1.Tables["Suppliers"];
    view.AllowDelete = true;
    view.AllowEdit = true;
    view.AllowNew = true;
    view.RowFilter = "City = 'Berlin'";
    view.RowStateFilter = DataViewRowState.ModifiedCurrent;
    view.Sort = "CompanyName DESC";

    // Simple-bind to a TextBox control
    Text1.DataBindings.Add("Text", view, "CompanyName");
}

Note: You have to note since the filtering and sorting would be done on client side it might perform really poorly if you have too much rows.

RageZ