473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

reader inside a reader

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
Nov 7 '07 #1
3 1714
Outside of the technical issue.
That is kind of a very bad idea.

Look at the NextResult() if you need multiple ResultSets.

You should hit the database 1 time, and use multiple ResultSets
(NextResult() ) if you need data from more than 1 query.

....
"Guilherme Grillo" <we****@rncomtotal.com.brwrote in message
news:e$**************@TK2MSFTNGP02.phx.gbl...
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


Nov 7 '07 #2
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
Nov 7 '07 #3

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

Nov 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bruce Wolfe | last post by:
We are developing an application using C#.net and we need to provide support for screen readers. Jaws works pretty good except that it can't read group box labels on dialog forms. The same version...
2
by: lewixlabs | last post by:
Hello, I have to develop an application which use Microsoft Fingerprint Reader. This device can be handled like a scanner? So can i use a class inside Platform SDK or API? There are resources?...
2
by: Kai | last post by:
Hi, I am looking for a Bar code reader softwre to read (Scan) bar code to MS-Access database table, I tried on the Web, but donn't know which one is good. Please help for recomanding one. ...
1
by: Aaron | last post by:
I asked for a script that can read info inside a specific xml tag and someone gave me this example. XmlReader reader = new XmlTextReader( filename ); while ( reader.Read() ) { if (...
5
by: Serdar C. | last post by:
hello everyone, i have a question about retrieving data from a bar code reader plugged in keyboard port (ps/2) i really dont know how to retrieve data from keyboard, i tried some methods but all i...
8
by: Saurabh | last post by:
Hi, I am getting the below mentioned error when I try to update a table Exception: Unable to update Person records Exception : System.Data.SqlClient.SqlException: Timeout expired. The...
1
by: simonZ | last post by:
I have data reader(I can't create data adapter, because I'm using command.BeginExecuteReader and EndExecuteReader) What is the best way to save data reader to table inside the data set? Any...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, how do you resolve this problem? i have a public procedure in my DataAccessLayer that gets a SqlDataReader how do i close the reader from inside the DataAccessLayer if I'm returning...
1
by: cmrhema | last post by:
hello i have some values inside a data reader which I display as below now while reading i want to store all values in an array. How do I do that ie. instead of response.write i should declare an...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.