query dataset using LINQ

6.2k views Asked by At

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

3

There are 3 answers

0
Vinod On
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();
1
Neha On
   var query = from e in DS1.emp

            where e.status == "out"


            select e;



dataGridView1.DataSource = query.AsDataView();
5
Niranjan Singh On

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