sqldatareader

Can we use sqldatareader to get data from two different MS SQL DB and tables? Sample



dim mycnstr as string = webconfig.....
dim con as new sqlconnection(mycnstr)
dim mycomnd as new sqlcommand("mystroprocedure", con)

try
con.open
dim myreader as sqldatareader = mycomnd.executedatareader
while myreader.reader

'put data my my labels

catch

end  
VBdotnet2005Asked:
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.

rpkhareCommented:
Ya, but you need to define two connection strings. You then need to pass each connection one-by-one to the DataReader.
0
VBdotnet2005Author Commented:
How would you modify my sample code?  Can I still use the same stored procedure?
dim mycnstr as string = webconfig.....
dim con as new sqlconnection(mycnstr)
dim mycomnd as new sqlcommand("mystroprocedure", con)

try
con.open
dim myreader as sqldatareader = mycomnd.executedatareader
while myreader.reader

'put data my my labels

catch

end  
0
rpkhareCommented:
dim mycomnd1 as new sqlcommand("StoredProcedure1", CN1)
dim mycomnd1 as new sqlcommand("StoredProcedure2", CN2)

DataReader1 = mycomnd1.ExecuteReader();
DataReader2 = mycomnd2.ExecuteReader();
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

VBdotnet2005Author Commented:
I am really sorry. This not what I want. I should had word my question correctly.  I want to use only one stored procedure, this storeprocedue does have an inner join ( from two different DB).  Can I still use sqldatareader to get data and display on each lables I want. Or you would use something else?
0
rpkhareCommented:
Is your stored procedure working correctly? It is correctly picking values from two DB?

You can call the same stored procedure in both Commands.
0
VBdotnet2005Author Commented:
Is your stored procedure working correctly?
Yes
 It is correctly picking values from two DB?
Yes

Do I still need to this ? "You can call the same stored procedure in both Commands." Or it is optional?
0
rpkhareCommented:
You need to pass the same stored procedure name.
0
VBdotnet2005Author Commented:
Like this?


dim mycnstr as string = webconfig.....
dim con as new sqlconnection(mycnstr)
dim mycomnd as new sqlcommand("mystroprocedure", con)
dim mycomnd2 as new sqlcommand("mystroprocedure", con)

try
con.open
dim myreader as sqldatareader = mycomnd.executedatareader
dim myreader2 as sqldatareader = mycomnd2.executedatareader

while myreader.reader

'put data my my labels


catch

end  
0
rpkhareCommented:
But you are passing same connection string. You need two connection string for each database.
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
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
ASP.NET

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.