i want to execute a SELECT-statement while anotherone still runs.
For better understanding i'll briefly explain my situation requirements:
i request "Trends" from a DB-Table "PW_Trends" and get up to 4 rows as a result.
There are typical fields like "TrendTitle", "TrendID", ... and so on.
Each of these Trends has (up to 8) Tags - to get those Tags i use the TrendID I get from the SELECT-statement above, as a parameter for another SELECT-statement in which I request "Tags" from a DB-Table "PW_Tags"
As you'll mayble already have noticed, i haven't closed the first DataReader before I open the other one - that's why I get the Error
"There is already an open DataReader associated with this Connection which must be closed first."
I understand the problem, but I am unsure about how to implement, so it will work best.
I think there are two ways I can handle this:
- I open the first DataReader
- I save all Trend-Data into arrays (very uncomfortable?)
- I close the first DataReader
- I open the 2nd one
- I use the saved TrendID in the array to fill the required Parameter of the 2nd SELECT-statement
- I close the 2nd DataReader
- I simply create another sqlConnection-object to use for the 2nd SELECT-statement (where the Connection-Parameters would be the same as in the first one)
I don't think it's a really good idea to use more than one sqlConnection at a time, particularly if they obtain exactly same parameters.
On the other side I don't like to mess with many arrays if not necessary.
that's why i would appreciate any comments, or even other ways to solve this problem,