Link to home
Start Free TrialLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

asked on

Delete a row in one dataset that matches the row of another dataset

I need to delete a row in one dataset that matches the row of another dataset :

        Dim row As DataRow
        For Each row In DSTemp.Rows
          . . . .
          if condition . . .

                 >>  I want to remove a row in "DataSet1" that matches the current row in "DSTemp", above

                    DataSet1.Tables(0).Rows.Remove(  --  the row that matches DSTemp --  )  ???


Note: datasets  DSTemp and DataSet1 are identical
Is it possible to get the "index" or current position of DSTemp and set it to DataSet1?
I have the primary key field:   row("ProductID")          thanks
Avatar of SandeepRR
SandeepRR
Flag of United States of America image

Hi MikeMCSD,

I got the solution for ur problem

u have to write the code for doing that operation the caode will be as follows,
------------------------------------
                                               DataSet ds = new DataSet();
                  ds = (DataSet)Session["Dataview"];

                  DataSet ds2  =new DataSet();
                  ds2 = (DataSet)Session["Data"];

                  for(int i=0; i<=ds.Tables[0].Rows.Count -1;i++)
                  {
                        DataRow re;
                        re = ds.Tables[0].Rows[i];
                        for(int j=0; j<=ds.Tables[0].Rows.Count -1;j++)
                        {
                              DataRow re1;
                              re1 = ds2.Tables[0].Rows[j];
                              if (re[0].ToString() == re1[0].ToString())                                 {
                                          ds2.Tables[0].Rows.RemoveAt(j);
                                          DataGrid2.DataSource = ds2;
                                          DataGrid2.DataBind();
                                 }

                        }
                  }
-----------------------------------------

actauly i was calling this method on two dataset
ds and ds1

ds has 2 rows and ds1 has 4 rows out of witch 2 are iedentical to the ds rows(Both the database has onle one table and with same schema)

and calles this code on button click
ans used to session veriable to get the dataset back in the dataset object,

for the folowing line of code

u might have to change the value in place of 0 actually it represent the primary key column in the table.
if (re[0].ToString() == re1[0].ToString())



Regards
SandeepRR
Avatar of MikeMCSD

ASKER

thanks Sandee . . but this is a Windows app. so I can't use Session, and
I'm using VB . . so I'm sure how to convert a lot of it.
ok u can skip the session actuaaly i have implemented this code in Webapplication on Button click, and for retaining the dataset i am using the session.

u can jst remove the session veriable and write the remaining code in the VB

and if u want take this link for C# to VB convertion
 
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

SandeepRR
ASKER CERTIFIED SOLUTION
Avatar of SandeepRR
SandeepRR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial