Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. use datareader browse dataabse???

use datareader browse dataabse???

Scheduled Pinned Locked Moved ASP.NET
helpcsharpphpasp-netdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cool_man
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • C cool_man

      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

      P Offline
      P Offline
      Pratik Desai
      wrote on last edited by
      #2

      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)

      C 1 Reply Last reply
      0
      • P Pratik Desai

        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)

        C Offline
        C Offline
        cool_man
        wrote on last edited by
        #3

        Thank you very much. It's different with asp3, we can use only one connection for all recordset.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups