473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Remove DataTable Entries

I have two DataTables, A and B. Both have the primary key "CID". How do I
remove all entries in Table A from Table B (with the same PK)?
Nov 15 '05 #1
1 15717
Hi Michael. Also, DataTable.Select( string) should work...
[But I'm not sure if it works on just the primary key field or all columns in the data row because it returns an array of datarows...]

Derek LaZard

"Michael Lang" <m@l.com> wrote in message news:eS**************@TK2MSFTNGP09.phx.gbl...
To delete a row from a DataTable, just call the "Delete" method on the
DataRow you want to delete. Do NOT call "DataTable.Rows.Remove(datarow
dr)". The Remove method of the DataRowCollection only removes it from the
collection, which will not be queued for deletion from the database.

As for how you determine what to delete? As far as I know, there is no
automated way to determine which records have the same field values (PK or
otherwise) in two tables?

My intial idea would be to loop through one table, and for each item check
for an item of the same PK value in the second table. If one exists, call
the Delete method on it as I noted above.

DataTable dtA = ...;
DataTable dtB = ...;
for (int i=0; i < dtA.Count; i++)
{
DataRow drA = dtA.Rows[i];
object pkA = ... primary key value in drA ...
DataRow drFound = dtB.Rows.Find(pkA);
if (drFound != null)
{
drFound.Delete();
}
}

I haven't run this code, I just made it up from looking at the help. In
theory, it should work. For details look at the help on DataTable,
DataRowCollection, and DataRow.

Michael Lang

"frank" <fr***@frank.com> wrote in message
news:ey**************@TK2MSFTNGP11.phx.gbl...
I have two DataTables, A and B. Both have the primary key "CID". How do I
remove all entries in Table A from Table B (with the same PK)?


Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: m|sf|t | last post by:
All, Is it possible to use PHP to open/read a TXT file (i.e. IP.TXT) that contains ip addresses (1 per line), remove any duplicates found, and re-write the file back out to IP_NEW.TXT ? The...
1
by: Odd Bjørn Andersen | last post by:
DB2 Enterprise Server Edition, version 8.1 (fixpack 6a) on Windows 2003. Is there a command to remove old entries both from Journal or old storage snapshots. Storage snapshots is saved in the...
6
by: ebc | last post by:
Hi, I have written a function that removes double entries from a sorted array. See the structures typedef struct tagRECR { char name;
14
by: BarrySDCA | last post by:
I have a database being populated by hits to a program on a server. The problem is each client connection may require a few hits in a 1-2 second time frame. This is resulting in multiple database...
1
by: Allerdyce.John | last post by:
I have a vector of Pair of int: typedef pair<int, int> MyPair; typedef vector <MyPair > MyVector I would like to remove entries if their first are equal, or if their value is swap ( first of...
2
by: =?ISO-8859-15?Q?Ma=EBl_Benjamin_Mettler?= | last post by:
Hello list! I need to repopulate PyGTK ComboBox on a regular basis. In order to do so I have to remove all the entries and then add the new ones. I tried to remove all entries like that: def...
7
by: WhiteClaw48 | last post by:
I'm working on an app that takes live data that is constantly fed in and lists it in a datagrid on a webpage. So it gets an entry and feeds it to the webpage. Then what I'd like to happen next...
0
by: wiredteknologies | last post by:
I'm trying to remove ACE's from Group ACL's using vb.net. Here is the sub i'm using: Public Sub fixacl(ByVal grouppath As String) Dim oSecurityDescriptor As New...
1
by: thesti | last post by:
hello, i want to update database (it's MySQL so i'm using mysqldotnetconnector provided by them) using the DataAdapter. update goes well, but when i remove a row from the dataTable by using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.