byrmol Blog

Garbage

DataTable Relational Operators in C# - Introduction

First off please excuse the title. A DataTable is to a relation as a dog is to a cat.

For those not .NET aware, a DataTable is the fundamental result set returned from the ADO.NET providers.
A DataSet is a collection of DataTables with a few features chucked in to simulate a In-Memory DBMS (IMDBMS).

As a side note, I was very excited when I heard that MS was building a IMDBMS.
But my hopes where shattered when I heard that they had dropped it to concentrate on the DataSet implementation.
I blame XML for this decision and for making me write the code that would have already been there if the IMDBMS project went ahead.

Lately I have been at the sharp end of the stick when in comes to manipulating DataSet and DataTable data.
Our data sources are DB2 on the mainframe and SQL Server. Data is delivered to us via a web service call.

Because business changes, sometimes the middle tier cannot be updated in time to consolidate these 2 data sources,
So it is left to us to manipulate 2 different data sources on the client to reflect these business changes.

Very simple cases can be handled by the in built functionality of the DataTable.
The SELECT method in a DataTable is basically the WHERE equivalent in TSQL.
But beyond simple restriction, the effort needed to perform any of the other relational operators is a bothersome task.

In our case, we needed JOIN, INTERSECT, MINUS (Difference) and DIVIDE.
A search on the net found that MS had already written a "helper" class that handles the JOIN operator MS Site

Personally I didn't like the code so I decided to re-write the JOIN method as well as implement the other operators.
I have left out RESTRICT as it is already implemented as the SELECT method of the DataTable.

So that left us with: JOIN, UNION, INTERSECT, DIFFERENCE, PRODUCT, DIVIDE, PROJECT.

Each of the methods have various overloaded signatures and could easily be extended to make life a little bit easier.
I am hoping to dedicate a post for each of these operators if enough people are interested. Leave a comment if your are.

Legacy Comments


robvolk
2004-01-13
re: DataTable Relational Operators in C# - Introduction
Whaddya waiting for? POST IT! :)

Shannon J Hager
2004-01-14
re: DataTable Relational Operators in C# - Introduction
I'll second that.

Andrew Coats
2004-01-19
re: DataTable Relational Operators in C# - Introduction
I would love to see/ try out the code. I found the JOIN on Microsoft's site but wanted it in c# and was too lazy to convert it to c#.

brainman
2004-01-19
re: DataTable Relational Operators in C# - Introduction
I can't wait!!!

Eric Johnson
2004-02-17
re: DataTable Relational Operators in C# - Introduction
yes, the Micro$oft helper code I wasn't too impressed with, either. Let's see what you got in the next few days. Otherwise, I've got to do it myself.

Guran Baksh
2004-02-24
re: DataTable Relational Operators in C# - Introduction
What you are doing will be very helpful. I am very curious to see it. Please keep me posted if you can at guranbaksh@hotmail.com

Alle de Haas
2004-04-08
re: DataTable Relational Operators in C# - Introduction
I'm not a DB expert, but had to do the same chore with 2 heterogenious Data Sources. Felt kind of stupid because I'd expected methods, etc. from MS. Glad to see I wasn't. Great job here.

ZARA KHAN
2005-10-06
re: DataTable Relational Operators in C# - Introduction
waiting for the comment!!!!!!!!!!

alex
2005-11-03
re: DataTable Relational Operators in C# - Introduction
good

Raj
2005-11-18
re: DataTable Relational Operators in C# - Introduction
where can i find the intersect and other method..I also want to learn about the SQLops class..

Thanks
Raj

Nask
2006-01-13
re: DataTable Relational Operators in C# - Introduction
I´m waiting for the comment!!!!!!!!!!

Nask
2006-01-13
re: DataTable Relational Operators in C# - Introduction
I´m waiting for the comment!!!!!!!!!!

John
2006-08-14
re: DataTable Relational Operators in C# - Introduction
Yes, lets have it....

khaoula
2008-07-29
re: DataTable Relational Operators in C# - Introduction
I´m waiting for the comment!!!!!!!!!!
I really need the INTERSECT code

test
2009-02-12
re: DataTable Relational Operators in C# - Introduction
where is the code boss??

Network Services
2010-05-13
re: DataTable Relational Operators in C# - Introduction
Nice post , thank you for sharing ......

casino online
2010-10-06
re: DataTable Relational Operators in C# - Introduction
thanks for giving this detail.
give me some more detail about operators in C#.