PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
dataset tables
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
dataset tables
![]() |
dataset tables |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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/defaul...kb;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/...ngdataview.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" <rjl444@hotmail.com> wrote in message news:30901fd7.0405221848.5c48916b@posting.google.com... > 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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

