use datareader browse dataabse???
-
I want to browse data fields with 2 datareader but in ASP.NET is it not done? Example: I have a table: [category] ID int primary key, Name varchar, SubID int default=0 ID Name SubID 1 Design 0 2 Web 0 3 Coding 0 4 Asp 3 5 Php 3 In webpage I want to browse this table like: Coding --Asp 'child of Coding --Php 'child of Coding Design Web With this case, I had think, I use 2 query and 2 datareader(like recordset) query 1: I collect all ID with SubID=0 "select * from Category where SubID=0" then I make a datareader for this query: dim myReader As SQLDataReader myReader = oCmd.ExecuteReader() now I use this datareader to browse data: While myReader.Read() response.write(myReader.Item("Name") & "
") 'with each ID I want to browse its child Category 'I make query 2: "select * from Category where SubID="&myReader.Item("ID") 'then I make a new datareader this query2 'dim myReader2 As SQLDataReader myReader2 = oCmd2.ExecuteReader() 'browse Child for this ID While myReader2.read() response.write("--"&myReader2.Item("Name") & "
") End While myReader2.Close() End while myReader.Close() I seem right for asp code(use recordset) but ASP.net have error: 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. I try to replace with another Connection but I sitll error. Datareader in ASP.NET can not use like that??? anyone had experience with this case? Please help me, thanks -
I want to browse data fields with 2 datareader but in ASP.NET is it not done? Example: I have a table: [category] ID int primary key, Name varchar, SubID int default=0 ID Name SubID 1 Design 0 2 Web 0 3 Coding 0 4 Asp 3 5 Php 3 In webpage I want to browse this table like: Coding --Asp 'child of Coding --Php 'child of Coding Design Web With this case, I had think, I use 2 query and 2 datareader(like recordset) query 1: I collect all ID with SubID=0 "select * from Category where SubID=0" then I make a datareader for this query: dim myReader As SQLDataReader myReader = oCmd.ExecuteReader() now I use this datareader to browse data: While myReader.Read() response.write(myReader.Item("Name") & "
") 'with each ID I want to browse its child Category 'I make query 2: "select * from Category where SubID="&myReader.Item("ID") 'then I make a new datareader this query2 'dim myReader2 As SQLDataReader myReader2 = oCmd2.ExecuteReader() 'browse Child for this ID While myReader2.read() response.write("--"&myReader2.Item("Name") & "
") End While myReader2.Close() End while myReader.Close() I seem right for asp code(use recordset) but ASP.net have error: 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. I try to replace with another Connection but I sitll error. Datareader in ASP.NET can not use like that??? anyone had experience with this case? Please help me, thanksYour error message indicates that your command objects oCmd and oCmd2 might be using the same connection object. Make sure that they use different connections and your code will work. eg. oCmd = New SqlCommand(query1, connection1) oCmd2 = New SqlCommand(query2, connection2)
-
Your error message indicates that your command objects oCmd and oCmd2 might be using the same connection object. Make sure that they use different connections and your code will work. eg. oCmd = New SqlCommand(query1, connection1) oCmd2 = New SqlCommand(query2, connection2)