473,387 Members | 1,863 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,387 software developers and data experts.

Compare Two Datatables

I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP that
are not in the Excel table and vica versa. There are about 300 records in
each. Short of a brute force attack on this, does anyone have an elegant
way to list the non-matches in each table?

Thanks.

John
Jul 2 '08 #1
7 6110
John,

Loop trough your both tables with a for each dr as datarow in datatable.rows
and use than in the other table the rowcollection find with the key from dr
if it exist.

http://msdn.microsoft.com/en-us/libr...yk(vs.85).aspx

Cor
"John Wright" <ri**********@hotmail.comschreef in bericht
news:eL**************@TK2MSFTNGP06.phx.gbl...
>I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP that
are not in the Excel table and vica versa. There are about 300 records in
each. Short of a brute force attack on this, does anyone have an elegant
way to list the non-matches in each table?

Thanks.

John
Jul 2 '08 #2
If you really need to optimize you could progress in parallel in two sorted
lists (you'll have the initial sort cost, then you'll basically browse each
list once in parallel to find out the difference).

I would try that only once I'm 100% sure the simpelst approach is not quick
enough...

--
Patrice

"John Wright" <ri**********@hotmail.coma écrit dans le message de groupe
de discussion : eL**************@TK2MSFTNGP06.phx.gbl...
I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP
that are not in the Excel table and vica versa. There are about 300
records in each. Short of a brute force attack on this, does anyone have
an elegant way to list the non-matches in each table?

Thanks.

John
Jul 2 '08 #3
Doesnt SQL server have a compare on two databases as well?
-If the two have the same schema ?

I remember reading something up on this a while ago. I cannot remember if
it was "in code .net" or if it was part of the sql server options.

Might be a good quick way if this is a one time thing.
If it even exists of what I am talking about. - otherwise - sorry for the
post.

Miro
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:DF**********************************@microsof t.com...
John,

Loop trough your both tables with a for each dr as datarow in
datatable.rows
and use than in the other table the rowcollection find with the key from
dr if it exist.

http://msdn.microsoft.com/en-us/libr...yk(vs.85).aspx

Cor
"John Wright" <ri**********@hotmail.comschreef in bericht
news:eL**************@TK2MSFTNGP06.phx.gbl...
>>I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP
that are not in the Excel table and vica versa. There are about 300
records in each. Short of a brute force attack on this, does anyone have
an elegant way to list the non-matches in each table?

Thanks.

John
Jul 2 '08 #4
Thanks Cor for the suggestion. Now I guess this needs to get a little
Fuzzy. I need to do a like comparison search on the rows as well. Most of
the rows are the same, but there are some that are slightly different. For
example in on list the lastname will be Smith III (Smith the 3rd) while in
the other list it is just Smith. So I would like to make a 1 for 1
comparison at the row level as suggested then, use the unmatched names and
do a like search to provide the user of possible matches. Any suggestions
on doing a like search?

John
"Patrice" <http://www.chez.com/scribe/wrote in message
news:3F**********************************@microsof t.com...
If you really need to optimize you could progress in parallel in two
sorted lists (you'll have the initial sort cost, then you'll basically
browse each list once in parallel to find out the difference).

I would try that only once I'm 100% sure the simpelst approach is not
quick enough...

--
Patrice

"John Wright" <ri**********@hotmail.coma écrit dans le message de groupe
de discussion : eL**************@TK2MSFTNGP06.phx.gbl...
>I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP
that are not in the Excel table and vica versa. There are about 300
records in each. Short of a brute force attack on this, does anyone have
an elegant way to list the non-matches in each table?

Thanks.

John

Jul 2 '08 #5
Thanks Cor for the suggestion.

I'm not Cor ;-)
I need to do a like comparison search on the rows as well. Most of the
rows are the same, but there are some that are slightly different. For
example in on list the lastname will be Smith III (Smith the 3rd) while in
the other list it is just Smith. So I would like to make a 1 for 1
comparison at the row level as suggested then, use the unmatched names and
do a like search to provide the user of possible matches. Any suggestions
on doing a like search?
My understanding is that you would like to find "close" match. I saw once a
way to do that by computing the "editing distance" between two strings (it
gives the number of elementary editing operations that should be done to
pass from one to the other).

Try :
http://en.wikipedia.org/wiki/Levenshtein_distance

--
Patrice

Jul 2 '08 #6
John,

Then if you have found the row(in the other case there is no need for it of
course). Then start an innerloop using the columns.

It go's always like this.

You take the row with the less equal names and then (I type it here so see
it a little bit as pseudo code)

dim equal = true
\\\
for each colum as DataColumn in drInTheLoop.Columns
'For the columns you want to skip
if Not "ColumnNameA ColumnNameB".Contains(column.ColumnName) then
if not drInTheLoop.Item(column.Column) =
foundDataRow.Item(column.Column.ColumnName) then
if not equal = false then equal = false
end if
end if
end for
///

Be aware that looping seldom takes more time then a direct statement, as you
don't do it, then it is done behind the scene. DotNet is build around
collections.

Cor

"John Wright" <ri**********@hotmail.comschreef in bericht
news:eC**************@TK2MSFTNGP03.phx.gbl...
Thanks Cor for the suggestion. Now I guess this needs to get a little
Fuzzy. I need to do a like comparison search on the rows as well. Most
of the rows are the same, but there are some that are slightly different.
For example in on list the lastname will be Smith III (Smith the 3rd)
while in the other list it is just Smith. So I would like to make a 1 for
1 comparison at the row level as suggested then, use the unmatched names
and do a like search to provide the user of possible matches. Any
suggestions on doing a like search?

John
"Patrice" <http://www.chez.com/scribe/wrote in message
news:3F**********************************@microsof t.com...
>If you really need to optimize you could progress in parallel in two
sorted lists (you'll have the initial sort cost, then you'll basically
browse each list once in parallel to find out the difference).

I would try that only once I'm 100% sure the simpelst approach is not
quick enough...

--
Patrice

"John Wright" <ri**********@hotmail.coma écrit dans le message de
groupe de discussion : eL**************@TK2MSFTNGP06.phx.gbl...
>>I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP
that are not in the Excel table and vica versa. There are about 300
records in each. Short of a brute force attack on this, does anyone
have an elegant way to list the non-matches in each table?

Thanks.

John

Jul 3 '08 #7
Using this as an example I get the error about a primary key. Since these
tables are pulled from LDAP and an Excel spreadsheet there is no primary
key. Any other ideas on how to search without a primary key?
John
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:DF**********************************@microsof t.com...
John,

Loop trough your both tables with a for each dr as datarow in
datatable.rows
and use than in the other table the rowcollection find with the key from
dr if it exist.

http://msdn.microsoft.com/en-us/libr...yk(vs.85).aspx

Cor
"John Wright" <ri**********@hotmail.comschreef in bericht
news:eL**************@TK2MSFTNGP06.phx.gbl...
>>I have two datatables that I load. One I load from LDAP, the other gets
loaded from Excel. I need to check to see which names are in the LDAP
that are not in the Excel table and vica versa. There are about 300
records in each. Short of a brute force attack on this, does anyone have
an elegant way to list the non-matches in each table?

Thanks.

John

Jul 3 '08 #8

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

Similar topics

2
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables...
3
by: Simple Simon | last post by:
Hi, I'm filling DataTable1 with the filenames from within a directory, and filling another DataTable2 with filenames from a SQL Db table. I'd like to compare the two, and delete the files from...
4
by: sal | last post by:
Greets, All Converting array formula to work with datatables/dataset tia sal I finally completed a formula I was working on, see working code below. I would like to change this code so it...
1
by: adeelanjum2001 | last post by:
I have two datatables with same structure. i want to compare the values in each row. for example: datatable1.rows(0).item(0) = datatable2.rows(0).item(0) one way to compare the rows in datatable...
6
by: Al | last post by:
I'd like to know if there were any changes in the DataSet which was populated by reading XML file. 6 DataTables with data or just structure with no data inside of it. I think about this scenario:...
4
by: Jim Andersen | last post by:
Is there anything built into .NET that is good (or rather easy) at comparing ? I have some data (in an array). I make a copy of this array, and the user changes some of the data, or maybe he...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
0
by: StefanPienaar | last post by:
Hi Guys Is there any way in c# (or vb.net) to extract a datatable of data from a dataset with multiple datatables which has relationships set up (containing combined data from the datatables)? ...
1
by: pramod gupta | last post by:
How do I compare two large data tables A and B using linq and get the records which exist in DataTable A but does not exist in DataTable B.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.