I have three tables and my requirement is to fetch their records by using the parent record of each table.
So I have three queries. Here is a code sample:
First Query
SQLConnection con = new SQLConnection("connectionstring");
SQLCommand cmd1 = new SQLCommand (1stQuery,con);
SQLDataReader rs1 = cmd1.DataReader();
while (rs1.Read()) {
// Making 2nd Query, 2nd Query is using 1st Query result
SQLCommand cmd2 = new SQLCommand(2ndQuery,con);
SQLDataReader rs2 = cmd2.DataReader();
while (rs2.Read()){
//Making 3rd Query using 2nd Query result
}
}
It gives the error that there is already an open DataReader. I dont want to close the SQL connection and open it for each query, as this is bad for performance.
I want to use only one SQL Connection for all the queries.