0

I have received a data table from the SQL server and for now, I want to show those records that "vocId" is equal to 1. but the following code represents all records. what can I do to fix it?

image

 DataTable dt = new DataTable();
 DataTable dtFetch = new DataTable();

 dt = cls.sentencesFetch();

 var result = from r in dt.AsEnumerable()
              where r.Field<int>("vocId").ToString() == 1.ToString()
              select r;
 DataView view = result.AsDataView();
 dtFetch = view.Table;
 dgv.DataSource = dtFetch;
  • 1
    Why are you using "ToString()"? Why are you using view.Table? Try following : dgv.DataSource = null; DataTable resultTable = result.CopyToDataTable(); dgv.DataSource = resultTable; – jdweng Jan 28 '19 at 14:23
  • have you tried using the debugger? what does result return? – styx Jan 28 '19 at 14:26
  • 1
    Doesn't `view.Table` return the original source data? Been a hundred years since I've had to deal with this old `DataSet` stuff. Why can't you just do `dgv.DataSource = view`? – DavidG Jan 28 '19 at 14:27
  • it has been fixed with the following code: ``` DataView view = result.AsDataView(); dgv.DataSource = view; ```` but why haven't work my previous code? –  Jan 28 '19 at 15:01

0 Answers0