Accessing Data from two different Databases in the same dataset

Hello Experts,

I am using Visual Studio 2012 (C#) and SQL Server 2008. I would like to create a single DataSet in Visual Studio (C#) that accesses and binds tables from both separate databases.

I tried doing this by ...

1. Creating a new DataSet in C# (VS 2012)
2. Added a connection to each Database in Server Explorer (VS2012)
3. Added the desired objects from each database on the DataSet palette.

VS didn't would only allow me to choose one of the Database objects at a time. In other words I could only choose one of the databases at a time.

Does anyone know how to do this?

or

would it be better to use the Linked server function in SQL Server?

Thanks!
SaxitalisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Koen Van WielinkBusiness Intelligence SpecialistCommented:
Just to clarify, are you getting data from different databases on the SAME server, or different servers? If it's the same server you wouldn't need the linked server function in SQL at all, just use fully qualified names when referring to the respective database I think.
Either way, coming from a DB background rather than a .NET background, I'd handle this on the database side through a view or a stored procedure, then just link your .NET application to that instead. Easier to maintain in SQL I think.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
A DataSet is simply a container for DataTable objects, nothing else.

Because each DataTable needs to be built separately, simply use a different connection for each DataTable.

If you want to mix the data from two databases into a single table, then you do not need a DataSet. You might want to read my article on the subject.

You simply need a DataTable. And as suggested by Kown Van Wielink, this is better done at the database level, in a stored procedure. Call that stored procedure and use the result as your DataTable.
1
SaxitalisAuthor Commented:
Yes I am accessing all databases on the same server so can use fully qualified naming in my queries. I was able to get my data displayed using a ReportViewer object. Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.