Yeah, while dataReaders are better performance oriented..
If your choice is between.... A reader with a nested reader...... VS a
dataset (preferably a strongly typed dataset)... then I would go with the
DataSet .........
If you're dealing with < 1000 records (you didn't say, so I don't really
know)... heck even <10,000 records.. then use the DataSet.
The nested reader just seems ... like the wrong plan of attack.
....
Another way to put it, use the dataset over the datareader until you have
reason (memory footprint) not to.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:22**********************************@microsof t.com...
You should be able to accomplish what you want with a SQL Subselect / join
and return the results as a DataSet with multiple tables and
datareleations
you can set.
Or, if you want a "Sub reader", follow the instructions in the exception
message and use a separate SqlCommand object for it.
-- Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"Guilherme Grillo" wrote:
>Friends,
Can I execute a Reader inside a Reader?
Example:
while (readerPerguntas.Read())
{
// Puxa as Informações da Tabela de Perguntas
string pergunta = (string)readerPerguntas["Pergunta"];
string dboPerguntaResposta = (string)readerPerguntas["Resposta"];
// Cria um Label com cada pergunta
Label labelPergunta = new Label();
labelPergunta.Text = "<p>" + pergunta + "</p>";
panelPesquisa.Controls.Add(labelPergunta);
// Comando que faz uma busca nas respostas da determinada pergunta
commRespostas = new SqlCommand("SELECT * FROM" + dboPerguntaResposta +
"",
conn);
// Executa o Comando
readerRespostas = commRespostas.ExecuteReader(); <<<< THIS LINE GET AN
EXCEPTION
EXCEPTION: There is already an open DataReader associated with this
Command
which must be closed first.
What can I do?
Sorry my English.
Grillo