473,898 Members | 2,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15747
Hi Michael. Also, DataTable.Selec t( 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******** ******@TK2MSFTN GP09.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 DataRowCollecti on 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(p kA);
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,
DataRowCollecti on, and DataRow.

Michael Lang

"frank" <fr***@frank.co m> wrote in message
news:ey******** ******@TK2MSFTN GP11.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
8658
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 reason is, I have ips coming from several sources, i.e. URLSCAN logs, MySQL dbs, etc. and I can use a DISTINCT on the individual queries, but I then combine all the results into 1 file which may contain duplicates. Thanks.
1
1497
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 systools schema of the database, and old entries in Journal are in the toolsdb. So it should be possible to write SQL that removes old entries for both of these. Has anybody found out how to do this ? Regards Odd Bjørn Andersen ErgoGroup Oslo,...
6
2965
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
21994
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 entries - all exactly the same, except the event_id field, which is auto-numbered. I need a way to query the record w/out duplicates. That is, any records exactly the same except event_id should only return one record. Is this possible??
1
5294
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 first pair equals to seconds of second pair): bool equals(MyPair src, MyPair dest ) { if (( src.first == dest.first) && ( src.second == dest.second))
2
6109
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 clear_comboboxes(boxreference): try: while True: boxreference.remove_text(0)
7
1376
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 is when a new entry feeds in. I'd like that new entry to first go through the other entries and see if there are any matches. If there are other matches then they should remove themselves from the page. The catch is this: The one column I'm...
0
883
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 ActiveDs.SecurityDescriptor Dim dacl As New ActiveDs.AccessControlList Dim ace As New ActiveDs.AccessControlEntry Dim group As New DirectoryServices.DirectoryEntry(grouppath) 'On Error Resume Next
1
2371
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 myTable.rows.remove(theRow). and then i want to update the tabe by using the myTable.getChanges i get the following error Value cannot be null. parametere name : dataTable does removing a row by calling the rows.remove is included in the changes...
0
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9840
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10857
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10483
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4706
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.