Home All Groups Group Topic Archive Search About

how to pull/query data from 2 Databases into 1 table using .Net?

Author
16 May 2006 9:58 PM
Rich
Hello,

I need to pull data from 2 tables that reside on the same sql server but 2
different databases.  In Query Analyzer I can say this

select t1.*, t2.* from tbl1 t1 join database2.dbo.tbl1 t2 on t1.RecordID =
t2.RecordID

The .Net sql command object does not appear to support this kind of syntax. 
I need to populate one datagridview with the data from DB1.tbl1 and
DB2.tbl1.  Is there a way to do this?

Thanks,
Rich

Author
16 May 2006 10:05 PM
Rich
Well, it turns out that the Sql Command object does support this kind of
syntax.  It seems that I left out the reference to DB2 in my sql string. 
Bummer man!

Show quoteHide quote
"Rich" wrote:

> Hello,
>
> I need to pull data from 2 tables that reside on the same sql server but 2
> different databases.  In Query Analyzer I can say this
>
> select t1.*, t2.* from tbl1 t1 join database2.dbo.tbl1 t2 on t1.RecordID =
> t2.RecordID
>
> The .Net sql command object does not appear to support this kind of syntax. 
>  I need to populate one datagridview with the data from DB1.tbl1 and
> DB2.tbl1.  Is there a way to do this?
>
> Thanks,
> Rich
>
>
Author
16 May 2006 10:17 PM
Liz
"Rich" <R***@discussions.microsoft.com> wrote in message
news:7BE0B3AE-F158-4D43-91A7-450341EE6869@microsoft.com...
> Hello,
>
> I need to pull data from 2 tables that reside on the same sql server but 2
> different databases.  In Query Analyzer I can say this
>
> select t1.*, t2.* from tbl1 t1 join database2.dbo.tbl1 t2 on t1.RecordID =
> t2.RecordID
>
> The .Net sql command object does not appear to support this kind of
> syntax.

why not ?  what does it do ?
Author
16 May 2006 10:48 PM
Rich
I made a mistake.  The sql command does support select t1.*, t2.* from tbl1
t1 join DB2.dbo.tbl1 t2 on t1.RecID = t2.RecID

My app works now.

Show quoteHide quote
"Liz" wrote:

>
> "Rich" <R***@discussions.microsoft.com> wrote in message
> news:7BE0B3AE-F158-4D43-91A7-450341EE6869@microsoft.com...
> > Hello,
> >
> > I need to pull data from 2 tables that reside on the same sql server but 2
> > different databases.  In Query Analyzer I can say this
> >
> > select t1.*, t2.* from tbl1 t1 join database2.dbo.tbl1 t2 on t1.RecordID =
> > t2.RecordID
> >
> > The .Net sql command object does not appear to support this kind of
> > syntax.
>
> why not ?  what does it do ?
>
>
>
>
>
>