PC Review


Reply
Thread Tools Rate Thread

Distributed Data into Common Dataset

 
 
Ed Warren
Guest
Posts: n/a
 
      18th Feb 2005
Problem:
I have two databases db1, db2

db1 contains a table with a keyfield ID (ms Access -- oleDbconnection1)
db2 contains a table with a keyfield ID (SQL server -- SqlConnection1)

I have generated two datasets from these tables

DS1 and DS2

What I need is a Dataset (DS3) implementing the following logic

Select all the ID's from DS1 that have no matching ID's in DS2 then put them
in DS3


If I had the two tables in the same database I would have the following
query:


SELECT DS1.ID
FROM DS1 LEFT JOIN DS2 ON DS1.ID = DS2.ID
WHERE (((DS2.ID) Is Null));

Question, How do I do this in ADO.Net when the tables are not in the same
database (require different connection objects)


Thanks in advance

Ed Warren


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Qm9ubmllIEJlcmVudCBbQyMgTVZQXQ==?=
Guest
Posts: n/a
 
      19th Feb 2005
Try this (off the top of my head, sorry if there's any typos):

DataRow[] rows;
DataRow row;

for (int i=0; i < ds1.Tables[0].Rows.Count)
{
rows = ds2.Tables[0].Select("keyfield = " + ds1.Tables[0]["keyfield"])
if (rows.Length == 0)
{
row = ds3.Tables[0].NewRow();
row["keyfield"] = ds1.Tables[0]["keyfield"];
ds3.Tables[0].Rows.Add(row);
}
}

~~Bonnie

"Ed Warren" wrote:

> Problem:
> I have two databases db1, db2
>
> db1 contains a table with a keyfield ID (ms Access -- oleDbconnection1)
> db2 contains a table with a keyfield ID (SQL server -- SqlConnection1)
>
> I have generated two datasets from these tables
>
> DS1 and DS2
>
> What I need is a Dataset (DS3) implementing the following logic
>
> Select all the ID's from DS1 that have no matching ID's in DS2 then put them
> in DS3
>
>
> If I had the two tables in the same database I would have the following
> query:
>
>
> SELECT DS1.ID
> FROM DS1 LEFT JOIN DS2 ON DS1.ID = DS2.ID
> WHERE (((DS2.ID) Is Null));
>
> Question, How do I do this in ADO.Net when the tables are not in the same
> database (require different connection objects)
>
>
> Thanks in advance
>
> Ed Warren
>
>
>

 
Reply With Quote
 
Ed Warren
Guest
Posts: n/a
 
      19th Feb 2005
Thanks for the suggestion, I think that will do it, however, I was hoping
there was a more 'elegant' solution using Ado.net.

Ed Warren.


"Bonnie Berent [C# MVP]" <(E-Mail Removed)> wrote
in message news:8CF2683B-A7C7-4884-A740-(E-Mail Removed)...
> Try this (off the top of my head, sorry if there's any typos):
>
> DataRow[] rows;
> DataRow row;
>
> for (int i=0; i < ds1.Tables[0].Rows.Count)
> {
> rows = ds2.Tables[0].Select("keyfield = " + ds1.Tables[0]["keyfield"])
> if (rows.Length == 0)
> {
> row = ds3.Tables[0].NewRow();
> row["keyfield"] = ds1.Tables[0]["keyfield"];
> ds3.Tables[0].Rows.Add(row);
> }
> }
>
> ~~Bonnie
>
> "Ed Warren" wrote:
>
>> Problem:
>> I have two databases db1, db2
>>
>> db1 contains a table with a keyfield ID (ms Access -- oleDbconnection1)
>> db2 contains a table with a keyfield ID (SQL server -- SqlConnection1)
>>
>> I have generated two datasets from these tables
>>
>> DS1 and DS2
>>
>> What I need is a Dataset (DS3) implementing the following logic
>>
>> Select all the ID's from DS1 that have no matching ID's in DS2 then put
>> them
>> in DS3
>>
>>
>> If I had the two tables in the same database I would have the following
>> query:
>>
>>
>> SELECT DS1.ID
>> FROM DS1 LEFT JOIN DS2 ON DS1.ID = DS2.ID
>> WHERE (((DS2.ID) Is Null));
>>
>> Question, How do I do this in ADO.Net when the tables are not in the same
>> database (require different connection objects)
>>
>>
>> Thanks in advance
>>
>> Ed Warren
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Qm9ubmllIEJlcmVudCBbQyMgTVZQXQ==?=
Guest
Posts: n/a
 
      19th Feb 2005
"Ed Warren" wrote:

> Thanks for the suggestion, I think that will do it, however, I was hoping
> there was a more 'elegant' solution using Ado.net.


I doubt it ... at least I can't think of anything else. This is probably as
"elegant" as it gets. <g>

~~Bonnie


>
> Ed Warren.
>
>
> "Bonnie Berent [C# MVP]" <(E-Mail Removed)> wrote
> in message news:8CF2683B-A7C7-4884-A740-(E-Mail Removed)...
> > Try this (off the top of my head, sorry if there's any typos):
> >
> > DataRow[] rows;
> > DataRow row;
> >
> > for (int i=0; i < ds1.Tables[0].Rows.Count)
> > {
> > rows = ds2.Tables[0].Select("keyfield = " + ds1.Tables[0]["keyfield"])
> > if (rows.Length == 0)
> > {
> > row = ds3.Tables[0].NewRow();
> > row["keyfield"] = ds1.Tables[0]["keyfield"];
> > ds3.Tables[0].Rows.Add(row);
> > }
> > }
> >
> > ~~Bonnie
> >
> > "Ed Warren" wrote:
> >
> >> Problem:
> >> I have two databases db1, db2
> >>
> >> db1 contains a table with a keyfield ID (ms Access -- oleDbconnection1)
> >> db2 contains a table with a keyfield ID (SQL server -- SqlConnection1)
> >>
> >> I have generated two datasets from these tables
> >>
> >> DS1 and DS2
> >>
> >> What I need is a Dataset (DS3) implementing the following logic
> >>
> >> Select all the ID's from DS1 that have no matching ID's in DS2 then put
> >> them
> >> in DS3
> >>
> >>
> >> If I had the two tables in the same database I would have the following
> >> query:
> >>
> >>
> >> SELECT DS1.ID
> >> FROM DS1 LEFT JOIN DS2 ON DS1.ID = DS2.ID
> >> WHERE (((DS2.ID) Is Null));
> >>
> >> Question, How do I do this in ADO.Net when the tables are not in the same
> >> database (require different connection objects)
> >>
> >>
> >> Thanks in advance
> >>
> >> Ed Warren
> >>
> >>
> >>

>
>
>

 
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
Common dataset for VB.Net Harsha Shah Microsoft VB .NET 0 3rd Jul 2005 06:48 AM
Common dataset for VB.Net Harsha Shah Microsoft VB .NET 0 3rd Jul 2005 06:48 AM
RE: Common dataset for VB.Net =?Utf-8?B?UGF1bCBOZWxzb24=?= Microsoft VB .NET 1 1st Jul 2005 11:09 AM
Re: Common dataset for VB.Net Cor Ligthert Microsoft VB .NET 0 19th Jun 2005 12:29 PM
Common dataset for VB.Net Cor Ligthert Microsoft VB .NET 0 19th Jun 2005 07:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:33 AM.