?
Solved

sqldatareader

Posted on 2008-11-11
9
Medium Priority
?
305 Views
Last Modified: 2012-05-05
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  
0
Comment
Question by:VBdotnet2005
  • 5
  • 4
9 Comments
 
LVL 8

Expert Comment

by:rpkhare
ID: 22936892
Ya, but you need to define two connection strings. You then need to pass each connection one-by-one to the DataReader.
0
 

Author Comment

by:VBdotnet2005
ID: 22936966
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
 
LVL 8

Expert Comment

by:rpkhare
ID: 22937005
dim mycomnd1 as new sqlcommand("StoredProcedure1", CN1)
dim mycomnd1 as new sqlcommand("StoredProcedure2", CN2)

DataReader1 = mycomnd1.ExecuteReader();
DataReader2 = mycomnd2.ExecuteReader();
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:VBdotnet2005
ID: 22937073
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
 
LVL 8

Expert Comment

by:rpkhare
ID: 22937096
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
 

Author Comment

by:VBdotnet2005
ID: 22937315
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
 
LVL 8

Expert Comment

by:rpkhare
ID: 22937738
You need to pass the same stored procedure name.
0
 

Author Comment

by:VBdotnet2005
ID: 22945869
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
 
LVL 8

Accepted Solution

by:
rpkhare earned 500 total points
ID: 22951838
But you are passing same connection string. You need two connection string for each database.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question