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.Ole Db" %>
<%
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=objC md.Execute Reader(Com mandBehavi or.CloseCo nnection)
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.
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.Ole
<%
Const sConnStr as String="Provider=Microsoft
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=objC
lstVendors.DataBind()
%>
<html>
<body>
<b>Departments</b>:
<asp:listbox id="lstVendors" runat="server" Rows="1"
DataTextField="VendorName"
</body>
</html>
</CODE>
any help would be appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.