Data from Two Databases

G

Guest

I am programming in visual basic dot net and I need a dataset built from
tables in two different databases. Is it possible to create connections to
both and then create a SQL command to open the dataset?

TIA
 
C

Cor Ligthert [MVP]

Helen,

You have to create one dataset, with two connections, two datatadapters and
two fills.

You can do that using the designer.

In code it is roughly typed

\\\
dim ds as new dataset
dim conn1 as new sqlconnection(connectionstring1)
dim conn2 as new sqlconnection(connectionstring2)
dim da1 as new sqldataadapter(sqlstring,conn1)
dim da2 as new sqldataadapter(sqlstring,conn2)
da1.fill(ds)
da2.fill(ds)
///
That is all without a try block. (The dataadapter takes care of the open and
close itself).

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top