Re: Compare Two Identical Datatable By Content
- From: amit_mitra <amitmitra@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Dec 2006 07:58:03 -0800
Hi
I think its the same thing again . Even if you override the operators the
logic of comparisn remains the same i.e we still need to traverse each
aggregated object of the datable one by one
"Ciaran O''''Donnell" wrote:
sorry, forgot you have to do the != if doing ==.
class MyDataTable : DataTable
{
public static bool operator==(MyDataTable dt1, MyDataTable dt2){
return dt1.Equals(dt2);
}
public static bool operator !=(MyDataTable dt1, MyDataTable dt2)
{
return !(dt1 == dt2);
}
public override bool Equals(object obj)
{
if (obj is DataTable && obj != null)
{
//Do Logic Here
return base.Equals(obj);
}
else
{
return false;
}
}
}
--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"Ciaran O''''Donnell" wrote:
You need to inherit from DataTable;
class MyDataTable : DataTable
{
public static bool operator==(MyDataTable dt1, MyDataTable dt2){
return dt1.Equals(dt2);
}
public override bool Equals(object obj)
{
if (obj is DataTable && obj != null)
{
//Do Logic Here
return base.Equals(obj);
}
else
{
return false;
}
}
}
--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"inpuarg" wrote:
On Mon, 18 Dec 2006 01:44:00 -0800, Ciaran O''Donnell
<CiaranODonnell@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
To be sure you would need to go through each cell in the entire table tillThis is not effective for me cause there are too many rows in the
you find the first difference.
datatables.
You could put shortcuts in first like,I can see in debug window that data are same. But c# says theese are
object.Equals to check if they are actually the same table, then compare row
counts and column counts, compare the schema (column datatypes). You could
try random sampling but it doesnt give you certainty.
not equal. Hashcodes are not same also. I think this is about .net 's
object compare model. Cause here is a sample :
Suppose that i have a class called Person :
public class Person
{
public string Name = "";
}
and let me test == operation :
Person a = new Person();
a.Name = "Person1";
Person b = new Person();
v.Name = "Person1";
if (a == b)
{
MessageBox.Show ("Equal");
}
else
{
MessageBox.Show("a : " + a.GetHashCode () + Environment.NewLine +
"b: " + b.GetHashCode() );
}
If you run this code you 'Ll see that theese objects are not equal.
Cause .net is not comparing theese objects due to their name 's
values (which is expected result - i am not against)
But there must be a way of overriding == operation for Person class
and make this comparison over Name 's values. And i know that this
exist too.
So here i am asking that is this possible for Datatable object ?
Is there such a method ? way , workarround etc.
- References:
- Compare Two Identical Datatable By Content
- From: inpuarg
- RE: Compare Two Identical Datatable By Content
- From: Ciaran O''Donnell
- Re: Compare Two Identical Datatable By Content
- From: inpuarg
- Re: Compare Two Identical Datatable By Content
- From: Ciaran O''''Donnell
- Re: Compare Two Identical Datatable By Content
- From: Ciaran O''''Donnell
- Compare Two Identical Datatable By Content
- Prev by Date: Reverse DNS Lookup - Need Ability to specify which DNS Server is contacted.
- Next by Date: business layer, data access layer , presentation layer for asp.net using C#.net
- Previous by thread: Re: Compare Two Identical Datatable By Content
- Next by thread: Re: Compare Two Identical Datatable By Content
- Index(es):
Relevant Pages
|