?
Solved

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

Posted on 2006-05-16
4
Medium Priority
?
360 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:MikeMCSD
  • 3
4 Comments
 
LVL 6

Expert Comment

by:SandeepRR
ID: 16697419
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
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 16699566
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.
0
 
LVL 6

Expert Comment

by:SandeepRR
ID: 16706156
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
0
 
LVL 6

Accepted Solution

by:
SandeepRR earned 2000 total points
ID: 16709972
Or u can user this code
--------------get ur two datasets-------------
Dim ds As DataSet = New DataSet ------first
Dim ds2 As DataSet = New DataSet --------second whose rows has to be deleted
---------

Dim i As Integer = 0
While i <= ds.Tables(0).Rows.Count - 1
 Dim re As DataRow
 re = ds.Tables(0).Rows(i)
 Dim j As Integer = 0
 While j <= ds.Tables(0).Rows.Count - 1
   Dim re1 As DataRow
   re1 = ds2.Tables(0).Rows(j)
   If re(0).ToString = re1(0).ToString Then
     ds2.Tables(0).Rows.RemoveAt(j)
     DataGrid2.DataSource = ds2
     DataGrid2.DataBind
   End If
   System.Math.Min(System.Threading.Interlocked.Increment(j),j-1)
 End While
 System.Math.Min(System.Threading.Interlocked.Increment(i),i-1)
End While

SandeepRR
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question