Passing a DataReader between Sub Procedures

Results 1 to 2 of 2

Thread: Passing a DataReader between Sub Procedures

  1. #1
    Join Date
    Dec 1969

    Default Passing a DataReader between Sub Procedures

    Greetings. <BR><BR>Here&#039;s what I want:<BR>When a user clicks a "Genre" radio button, a drop down list fills with available genres. When they click on the "CD Name" radio button, the same dropdown will fill with cd names.<BR><BR>Here&#039;s how I want to do it:<BR>Create two DataReaders in Page_Load, one full of "Genres" and one full of "CD Names" as pulled from my database. Then, when the user clicks on the radio button, a procedure is called which binds the dropdown to the appropriate DataReader. This will avoid multiple trips to the DB whenever a different radio button is selected.<BR><BR>Here&#039;s my question:<BR>I have the DataReaders in Page_Load. How do I make them "global" so that I can use them in ANY sub procedure WITHOUT having to re-declare them or connect to the DB multiple times? I&#039;d like to be able to refer to them in my "Sub_Dropdown_Fill" procedure which will bind the dropdown to one of the two DataReaders.

  2. #2
    Join Date
    Dec 1969

    Default RE: Passing a DataReader between Sub Procedures

    You can&#039;t do this with DataReaders. DataReaders are forward only, read only access. You will need to fill a dataset and then store that dataset in viewstate or cache. If you declare a variable globally(outside any sub), you will be able to access it from any sub.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts