Deleting rows after merging two datasets ?

Discussion in 'ASP.NET / ASP.NET Core' started by ashrafcsnet, Jun 16, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Please I would like to know how can I remove duplicated rows in a dataset Initiated from merging two datasets ?
     
  2. I'm not sure but I guess if I needed to I would first sort the DataSet unless I knew that the duplicated rows were always adjacent.
    Then I would for each row when I encountered a duplicate, remove it, call AcceptChanges() but now my foreach iterator is off so I would use a goto label and jump out to the label and begin the sequence again until finished.

    Hmm, now it seems that you can mark a DataSet row for deletion but it won't be deleted until later. If that's right then the foreach iterrator should not be invalidated so the goto/label pair might not be needed.

    Hmm, I wonder if one could do a Select on the DataSet rows and filter with a DISTINCT and if that worked then you'd be home free.
     
  3. Thanx dilton for you reply :) I'll try it :)
     
  4. If the dataset is huge, you could get better performance by (start with the dataset with duplicate rows) first create a Clone of the schema then iterate over the source table and ImportRow when you know it hasn't already been imported. You will know that if you sue a hashtable.
     
  5. This is from a google search and may be of help:

     
  6. It's not working ... I need HELP please
     
  7. If removing the duplicates isn't working out as you'd hoped; perhaps you can prevent the duplicates from occurring in the first place. Scott's post suggests that (and I have successfully used) methods to establish a relationship in the DataSet and enforce referential integrity.

    What isn't working?
     
  8. I solved the problem ....




    cmd1.CommandText = "SELECT CM_NO, CM_NAME, CM_ADDR_1, CM_TEL FROM Scott.CUSTOMER_AUH where CM_Name like '%" + txtName.Text.Trim().ToUpper() + "%'";


    da1.SelectCommand = cmd1;


    da1.Fill(ds1);


    ds1.Tables[0].Columns[ "CM_NAME" ].Unique = true;


    ds1.Tables[0].PrimaryKey=
    new DataColumn[] { ds1.Tables[0].Columns["CM_NAME"]};





    cmd2.CommandText = "SELECT CM_NAME, CM_ADDR_1 FROM SCOTT.CUSTOMER_AUH WHERE soundex(CM_NAME) L
    IKE soundex('" + txtName.Text.Trim() +"')";


    da2.SelectCommand = cmd2;





    da2.Fill(ds2);


    ds2.Tables[0].Columns[ "CM_NAME" ].Unique =
    true;


    ds2.Tables[0].PrimaryKey=
    new DataColumn[] { ds2.Tables[0].Columns["CM_NAME"]};


    .


    .


    .


    ds2.Merge(ds1,true,MissingSchemaAction.AddWithKey);


    The duplication was in all the field except the primary key filed in the Oracle table so I spacified explecitly the primary key for each table ...


    I don't know maybe I didn't mention the duplication with the other field ?? any wayzz thanx for ur cooperation "diltonm & scott" :)
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page