none
DataTable Select returns Error Columns... RRS feed

  • Question

  • Hi everyBody...

    I have a strange problem...
    When i make selection in a DataTable it return Error Columns...
    Let me show my codes..

    string sql = "SELECT id, name, surname, age FROM Persons";
    command.CommandText = sql;
    adapter.SelectCommand = command;
    adapter.Fill(ds);
    grid.DataSource = ds.Tables[0];

    in this code there is not any problem...
    But when i make a filtering like this...

    string filter = "age > 20";
    grid.DataSource = ds.Tables[0].Select(filter);

    it returns some RowError, RowState, Tables, HasErrors Columns...
    What is the problem...
    And how solve it...
    If you know the answer please tell me....
    Thanks

    PS My Database is Mysql...

    Friday, October 15, 2010 10:08 AM

Answers

  • Ok,

    Try with DataTAble

     

    DataRow[] drr2;

    drr2 = ds.Tables[0].Select(filter) ;


    DataTable dt = new DataTable ();


      dt = drr2.CopyToDataTable();

     

    grid.DataSource= dt .Tables[0];


    PS.Shakeer Hussain
    • Marked as answer by namco0088 Friday, October 15, 2010 11:56 AM
    Friday, October 15, 2010 11:11 AM

All replies

  • Hi,

    Try to use the below code to avoid your Errors.

     

    DataRow[] drr2;

    drr2 = ds.Tables[0].Select(filter) ;


    DataSet ds2 = new DataSet ();


      ds2 = drr2.CopyToDataTable();

     

    grid.DataSource= ds2.Tables[0];


    PS.Shakeer Hussain
    Friday, October 15, 2010 10:23 AM
  • it gives error

    Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.DataSet'

    Friday, October 15, 2010 10:34 AM
  • Ok,

    Try with DataTAble

     

    DataRow[] drr2;

    drr2 = ds.Tables[0].Select(filter) ;


    DataTable dt = new DataTable ();


      dt = drr2.CopyToDataTable();

     

    grid.DataSource= dt .Tables[0];


    PS.Shakeer Hussain
    • Marked as answer by namco0088 Friday, October 15, 2010 11:56 AM
    Friday, October 15, 2010 11:11 AM
  • Thank you Syed Shakeer Hussain

    But why my version doesnt work???

    Friday, October 15, 2010 11:57 AM