Datatable.importRows not working RRS feed

  • Question

  • private void txtName_TextChanged(object sender, EventArgs e)


    for (int i = 0; i < grdEditEmployees.Rows.Count; i++)


    if (grdEditEmployees.RowsIdea.Cells[3].Value.ToString().Substring(0, txtName.Text.Length) == txtName.Text)


    dataRows =ds.Tables[0].Select("EmployeeFirstName like '" + txtName.Text + "%'");


    for (int j = 0; j <= dataRows.GetUpperBound(0); j++)











    rows are imported  when i refreshes the grid, it shows nothing  and also table  still remains empty when i import rows in it  


    Friday, January 4, 2008 6:26 PM


  • dataRows is a collection of REFERENCES to the datatable contained in the dataset.


    When you run the ds.clear() method, this will clear the table, and thus your collection is a list of nulls/floating references.


    What you want to do is this:  Select the rows using your : dataRows =ds.Tables[0].Select("EmployeeFirstName like '" + txtName.Text + "%'");


    You cannot clear ds.tables[0] as it contains the rows you wish to import.


    Try importing them to a dummy table, then clearing table zero, then doing your import call from the new dummy table, then clearing the dummy table. 



    get rows to import.

    Place rows in temp.

    clear destination

    load rows from temp.

    clear temp.


    HOWEVER: It appears that your trying to filter the datagrid to show a row that is filtered by what the user types into txtName?  If I'm correct your much better off doing one of two things:


    If your using a bindingsource, set the bindingsource.filter = "EmployeeName like " + txtName.text + "%".


    If your not using a bindingsource, create a dataview like so:


    System.Data.DataView view = new System.Data.DataView(ds.tables[0]);


    then set the datagrids binding to the view.  You can then manipulate the view.filter property to achieve the same effect.

    Saturday, January 5, 2008 4:42 AM