PC Review


Reply
Thread Tools Rate Thread

dataset tables

 
 
joe klein
Guest
Posts: n/a
 
      23rd May 2004
Please help with this problem:
I have a sql DB table which I can load into a dataset and a XML file I
load into a seperate dataset. I need to compare these two datasets and
get a list off records that match a certain column. the SQL table and
the xml have the same db columns.
couple of questions:
1) Is this the best way?
2) If I need to use 2 tables in a dataset for this, how do I load an
XML doc into a specific table?
3) I assume I cannot run SQL query on these 2 objects (tables or
datasets), how would I get the records I need?

Thanks much in advanced.
Joe
 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      23rd May 2004
There are a bunch of ways but the first one is to sort the first one it's PK
field (you can create a Dataview on it) by using DataView dv =
DataSetName.Tables[TableIndex].DefaultView;

After it's sorted, walk through it and load the distinct values in an
ArrayList for instance so that you only have one instance of each uniquer
value. http://support.microsoft.com/default...b;en-us;326176 Now,
assume that you have the arraylist and that all the values are uinque.
Create A dataview on the second table (for simplicity I'm going to assume
that the PK value is an int). Walk throught the array list and at each
pass, set the rowfilter of the Second table (it doesn't mattter which
dataset it's in b/c you are using a View with both tables) to the PK of
listed inthe arraylist. If the value is there, you'll have only the
matching rows. If you want to see if they exist, you can simply iterate the
view (which will only have matching rows ) and you can use dv2.Count (which
will tell you how many matches you have on the PK, or you can walk through
each value of the second view and compare item by item to the first view's
rows. http://www.knowdotnet.com/articles/i...gdataview.html

bool RowsMissing = false;
for(int i = 0; i < myArrayListCount; i++){

dv2.RowFilter = "PKField = '" + (int)myArrayListCount[i] + "'";
if(dv2.Count == 0){RowsMissing = true;
//you can exit function or whatever b/c you know they dont'
match
}

Or, you can set the rowsfilter of both views. Then you can do a foreach on
the columns and rows, and at each pass check for equality, if they aren't
the same, then signal a difference and exit or wahtever. If you want to
list the changes you mayneed to create a collection of some sort to hold the
values and positions..not sure what the end game is here


Also, you can definitely use Select statements on DataTable objects and
between the DataView (which is only one line to create and very easy to use)
and DataTable objects, you can do some very fancy searching and filtering.
If you look through my Efficient Using ADO.NET xxxx
http://www.knowdotnet.com/williamryan.html series here and/or look for
..Expression in the search box, you'll find a lot of techniques (both simple
and complex) for searching and finding.

HTH,

Bill
--
W.G. Ryan MVP Windows - Embedded

www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/
"joe klein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Please help with this problem:
> I have a sql DB table which I can load into a dataset and a XML file I
> load into a seperate dataset. I need to compare these two datasets and
> get a list off records that match a certain column. the SQL table and
> the xml have the same db columns.
> couple of questions:
> 1) Is this the best way?
> 2) If I need to use 2 tables in a dataset for this, how do I load an
> XML doc into a specific table?
> 3) I assume I cannot run SQL query on these 2 objects (tables or
> datasets), how would I get the records I need?
>
> Thanks much in advanced.
> Joe



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet has no tables Jeremy Microsoft ADO .NET 1 6th Jul 2009 10:52 AM
DataSet Designer/adding multiple tables to a dataset/ how? =?Utf-8?B?Q3VydGlz?= Microsoft ADO .NET 1 21st Aug 2006 03:09 PM
How to update dataset.Tables["tab1"] from records in dataset.Tables["tab2"]? AndiSHFR Microsoft C# .NET 1 12th Jan 2006 07:41 AM
dataset tables juli jul Microsoft C# .NET 0 20th Mar 2005 12:08 PM
DataSet Tables into Access tables with Oledb? Nevyn Twyll Microsoft ADO .NET 6 2nd Sep 2004 09:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:56 PM.