Link to home
Start Free TrialLog in
Avatar of mychiefs58
mychiefs58

asked on

There is already an open DataReader associated with this Command which must be closed first.

I'm returning to coding after 10 years away.  I used asp way back in the day, but things are a bit different with asp.net.  Still, it's coming along a bit.  i'm try to build some pages to test out operability before I implement them as functional pages on our site.  And so far, for every problem I've come up against, I've found a solution pretty easily.  But I cannot solve this "there is already an open datareader" one.  I've found quite a bit about it, but it all seems to be so much more complex that what I'm doing here...and if I'm getting this error on a simple dropdown box (which will eventually provide consecutive dropdowns based on the option chosen here), I can imagine how frustrating it would be with a huge app with lots of data connections, etc.

Anyway, here's my simple, but not working, code.

<CODE>

<%@ Page aspcompat=true language="vb" debug="true"%>

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.OleDb" %>

<%
  Const sConnStr as String="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Northwind\PMTemp.mdb" & ";"
  Dim objConn as New OleDbConnection(sConnStr)
   
  objConn.Open()

  Const strSQL as String="SELECT VendorName, ID FROM Vendor"
  Dim objCmd as New OleDbCommand(strSQL, objConn)
 
 
  Dim objDR as OleDbDataReader
  objDR=objCmd.ExecuteReader()
   
  lstVendors.DataSource=objCmd.ExecuteReader(CommandBehavior.CloseConnection)
  lstVendors.DataBind()
 
%>

<html>
<body>
  <b>Departments</b>:
  <asp:listbox id="lstVendors" runat="server" Rows="1"
               DataTextField="VendorName" DataValueField="ID" />
               
         
</body>
</html>

</CODE>

any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial