PDA

View Full Version : su dung datareader thay the recordset???



snoopy
06-11-2003, 07:00
Chao cac ban, minh co 1 van de nay dang bi stuck ne`. Trong database minh co 1 table cau truc nhu sau:

[Category]
ID int primarykey
Name varchar
SubID int

Khi browing cac field ra web minh muon du lieu hien thi dang cay nhu:

Dien
->Dien tu
->Dien lanh
May mac
Tai Chanh
....

Trong asp minh su dung 2 recordset de dua du lieu ra:

'thuc hien query cho nhung ID cha
sql="select * from Category where SubID=0"
rs.open sql,conn

do while rs.eof
'thuc hien query cho nhung ID con
sql_2="select * from Category where ID="&rs("ID")
response.write rs("Name")&"<br>"
rs2.open sql_2,conn
do while rs2.eof
response.write "->"&rs2("Name")&"<br>"
rs2.movenext
loop
rs.movenext
loop

Nhung khi chuyen qua ASP.NET, minh dung 2 datareader thi IIS no k cho su dung 2 datareader no bao loi:

There is already an open DataReader associated with this Connection which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.

Vay trong asp.net khong cho mo 2 datareader 1 luc a? Vay de browing data nhu vay co cach nao k? Xin cac ban giup do minh nhe, thks

danceswithwolves
06-11-2003, 15:19
mỗi datareader đòi hỏi một opened connection riêng. Vậy, bạn cần 2 (opened) connections cho 2 datareaders sử-dụng-đồng-thời.

snoopy
07-11-2003, 09:45
mỗi datareader đòi hỏi một opened connection riêng. Vậy, bạn cần 2 (opened) connections cho 2 datareaders sử-dụng-đồng-thời.

Thank u very much