[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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.
0
mychiefs58
Asked:
mychiefs58
1 Solution
 
RejojohnyCommented:
>> objDR=objCmd.ExecuteReader()
  lstVendors.DataSource=objCmd.ExecuteReader(CommandBehavior.CloseConnection)

comment the first line
'objDR=objCmd.ExecuteReader()

or change the second line to
  lstVendors.DataSource=objDR
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now