Re: Call SqlCommand.ExecuteReader inside another SqlCommand.Execut



Que?

Do you mean that you are concerned that a row of interest in table2 could be
updated after you execute the select on table1 but before you execute the
inner select on table2?

Try, using one SqlDataReader

begin transaction;
select * from table1;
select * from table2 where pk in (select fk from table1);
end transaction;

When you have finished cycling through the SqlDataReader (table1) then
execute it's NextResult method and cycle through it again for table2.

You can do it one way or you can do it the other way, but you can't do it
both ways at once.


"David Thielen" <thielen@xxxxxxxxxxxxx> wrote in message
news:40940EA9-547A-458B-BCB6-1B8BD52E91DF@xxxxxxxxxxxxxxxx
Hi;

I need the transaction because otherwise I can end up with two objects
that
do not match. There must be a way to do this as it's pretty basic and I
think
a lot of people would need this.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"Stephany Young" wrote:

Any SqlConnection object can only have one active SqlDataReader at a
time.

To do what you need to do you need to have a second SqlConnection object
for
the inner SqlDataReader.

I do not think that a 'transaction' can span multiple connections.

It appears that you are only 'reading' so there does not appear to be any
need for a transaction.


"David Thielen" <thielen@xxxxxxxxxxxxx> wrote in message
news:B99A7816-4975-476B-B0D6-52C32359CA13@xxxxxxxxxxxxxxxx
ps - with all of this within the same transaction.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"David Thielen" wrote:

Hi;

I need to call SqlCommand.ExecuteReader and then inside a while
(reader.Read()) I need to call another SqlCommand.ExecuteReader. I
need
to do
this because I have a FK:PK relationship and based on the FK read,
then
read
the row in that related table - if the FK is not null.

How can I do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm







.



Relevant Pages