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.

Print | posted on Monday, January 12, 2004 2:57 PM

Feedback

# re: DataTable Relational Operators in C# - Introduction

left by robvolk at 1/13/2004 1:13 PM Gravatar
Whaddya waiting for? POST IT! :)

# re: DataTable Relational Operators in C# - Introduction

left by Shannon J Hager at 1/14/2004 6:37 AM Gravatar
I'll second that.

# DataTable and Relational Operators

left by Ashutosh Nilkanth's .NET Blog at 1/17/2004 6:13 PM Gravatar

# DataTable and Relational Operators

left by ShowUsYour at 1/17/2004 8:06 PM Gravatar

# re: DataTable Relational Operators in C# - Introduction

left by Andrew Coats at 1/19/2004 12:15 AM Gravatar
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#.

# DataTable and Relational Operators

left by Ashutosh Nilkanth's .NET Blog at 1/19/2004 10:04 PM Gravatar

# re: DataTable Relational Operators in C# - Introduction

left by brainman at 1/19/2004 11:59 PM Gravatar
I can't wait!!!

# re: DataTable Relational Operators in C# - Introduction

left by Eric Johnson at 2/17/2004 5:18 AM Gravatar
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.

# re: DataTable Relational Operators in C# - Introduction

left by Guran Baksh at 2/24/2004 2:06 PM Gravatar
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

# re: DataTable Relational Operators in C# - Introduction

left by Alle de Haas at 4/8/2004 9:41 PM Gravatar
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.

# re: DataTable Relational Operators in C# - Introduction

left by ZARA KHAN at 10/6/2005 1:59 AM Gravatar
waiting for the comment!!!!!!!!!!

# re: DataTable Relational Operators in C# - Introduction

left by alex at 11/3/2005 12:14 AM Gravatar
good

# re: DataTable Relational Operators in C# - Introduction

left by Raj at 11/18/2005 7:45 AM Gravatar
where can i find the intersect and other method..I also want to learn about the SQLops class..

Thanks
Raj

# re: DataTable Relational Operators in C# - Introduction

left by Nask at 1/13/2006 3:09 AM Gravatar
I´m waiting for the comment!!!!!!!!!!

# re: DataTable Relational Operators in C# - Introduction

left by Nask at 1/13/2006 3:09 AM Gravatar
I´m waiting for the comment!!!!!!!!!!

# re: DataTable Relational Operators in C# - Introduction

left by John at 8/14/2006 2:20 PM Gravatar
Yes, lets have it....

# re: DataTable Relational Operators in C# - Introduction

left by khaoula at 7/29/2008 7:51 PM Gravatar
I´m waiting for the comment!!!!!!!!!!
I really need the INTERSECT code

# re: DataTable Relational Operators in C# - Introduction

left by test at 2/12/2009 10:47 AM Gravatar
where is the code boss??

# re: DataTable Relational Operators in C# - Introduction

left by Network Services at 5/13/2010 3:08 PM Gravatar
Nice post , thank you for sharing ......

# re: DataTable Relational Operators in C# - Introduction

left by casino online at 10/6/2010 11:07 PM Gravatar
thanks for giving this detail.
give me some more detail about operators in C#.
Comments have been closed on this topic.