Closing Data Reader for Mulitple DropDownLists

Results 1 to 2 of 2

Thread: Closing Data Reader for Mulitple DropDownLists

  1. #1
    Join Date
    Dec 1969

    Default Closing Data Reader for Mulitple DropDownLists

    Anyone know of an example showing multiple drop down lists on the same page? All I&#039;ve seen have one. I have tried to set up multiple ones, but I get errors that the reader must be closed, and I can&#039;t seem to close it.<BR><BR>Code:<BR><BR> Sub Page_Load( s As Object, e As EventArgs )<BR> Dim myConnection As SqlConnection<BR> Dim myCommand As SqlCommand<BR> If Not isPostBack Then<BR> &#039; Get List of Categories From Database<BR> myConnection = New SQLConnection( "Server=sql-server;uid=username;pwd=password;Database=Petro" )<BR> myCommand = New SqlCommand( "Select height From attributemeasures", myConnection )<BR> myConnection.Open()<BR> category.DataSource = myCommand.ExecuteReader()<BR> category.DataTextField = ("height" )<BR> category.DataBind()<BR> category2.DataSource = myCommand.ExecuteReader()<BR> category2.DataTextField = ("height" )<BR> category2.DataBind()<BR><BR>error: There is already an open datareader. How would I close it? ( I usally do myDataReader.close() -- but that is not appropriate in this case)

  2. #2
    Join Date
    Dec 1969

    Default RE: Closing Data Reader for Mulitple DropDownLists

    so do that...<BR><BR>instead of taking the datareader straight from the execute method into the datasource... put it into a temp variable so you can close it when you&#039;re done with it<BR>----------------------------<BR><BR>myConnection.Open()<BR>dim dr as IDataReader = myCommand.ExecuteReader()<BR>category.DataSource = dr<BR>category.DataTextField = ("height" )<BR>category.DataBind()<BR>dr.close()<BR><BR>dr = myCommand.ExecuteReader()<BR>category2.DataSource = myCommand.ExecuteReader()<BR>category2.DataTextFie ld = ("height" )<BR>category2.DataBind()<BR>dr.close()<BR><BR>---------------<BR><BR>That should work

Posting Permissions

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