1

Possible Duplicate:
Not displaying data in gridview when applying filter to a dataset

I am having a Dataset ds with contents of table emp with ename , pass , status as attributes .

I want to query the Dataset uing LINQ such that it returns records whose status is "out"

it worked when used on datatable when i use dataset data is not displayed

Please tell me how can i achieve this.Thanks in Advance

Community
  • 1
  • 1
Vinod
  • 4,672
  • 4
  • 19
  • 26

3 Answers3

2

Simple use this and convert result to list:
First add a reference to System.Data.Extensions.dll (where LINQ over DataSet support is implemented)

// Fill the DataSet.
DataSet ds = new DataSet();
ds.Locale = CultureInfo.InvariantCulture;
FillDataSet(ds);

DataTable orders = ds.Tables["SalesOrderHeader"];

var query =
    from order in orders.AsEnumerable()
    where order.Field<string>("status") == "out"
    select order;

yourGridView.DataSource= query.ToList();
yourGridView.DataBind(); 

You can check this also:
Binding LINQ query to DataGridView

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
0
   var query = from e in DS1.emp

            where e.status == "out"


            select e;



dataGridView1.DataSource = query.AsDataView();
Neha
  • 2,933
  • 3
  • 19
  • 23
  • It will give compilation error "DS1.emp", you can not use Dataset as Datacontext. Instead AsEnumerable() Method will work here. – Pankaj Tiwari Jan 18 '12 at 05:57
0
OleDbDataAdapter da = new OleDbDataAdapter("select empname,pass,status from employees", conn);
        DataSet ds1=new DataSet();
        da.Fill(ds1,"emp");
            var datasource = from r in ds1.Tables["emp"].AsEnumerable()
                             where r.Field<string>("status")=="out"
                             select new{empname=r.Field<String>("empname"),status=r.Field<string>("status")};
            GridView1.DataSource = datasource;
            GridView1.DataBind();
Vinod
  • 4,672
  • 4
  • 19
  • 26