Not displaying data in gridview when applying filter to a dataset

My gridview is not displaying data when filter

protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection conn=new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Dynacs.accdb");
        OleDbDataAdapter da = new OleDbDataAdapter("select empname,pass,status from employees", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "emp");
        GridView1.DataSource = ds.Tables["emp"].Select("status='in'");
        GridView1.DataBind();
    }

Showing this when executed

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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();

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply