sodakotahusker
Programmer
- Mar 15, 2001
- 601
I am getting a message trying to populate two dropdownlists
There is already an open DataReader associated with this Connection which must be closed first.
I changed my code so each dropdown has its own reader object, own command object and own connection. I still get error. I am closing the sqlreader. Even if I comment out the first set of code I get the error on the 2nd set. If I comment out the 2nd set - the first dropdownlist populates perfectly and life is good. This is driving me nuts! Anyone see something I am doing wrong? Thanks!
Dim mySqlConnection As New SqlConnection("server=(local);Trusted_Connection=yes;database=localstuff")
mySqlConnection.open()
Dim mySqlConnection2 As New SqlConnection("server=(local);Trusted_Connection=yes;database=localstuff")
mySqlConnection2.open()
Dim objCommand As New SqlCommand("select cityname,cityid from locations order by cityname", mySqlConnection)
Dim sqlReader = objCommand.ExecuteReader()
cityNames.DataSource = sqlReader
cityNames.DataTextField = "cityname"
cityNames.DataValueField = "cityid"
cityNames.databind()
sqlreader.close()
objcommand = nothing
mySqlConnection.close()
Dim objCommand2 As New SqlCommand("select * from churchcategories order by churchcategory", mySqlConnection2)
Dim sqlReader2 = objCommand2.ExecuteReader()
sqlreader2 = objcommand2.executereader()
cbochurchcategories.DataSource = sqlReader2
cbochurchcategories.DataTextField = "churchcategory"
cbochurchcategories.DataValueField = "churchcategoryid"
cbochurchcategories.databind()
sqlreader2.close
mySqlConnection2.close()
There is already an open DataReader associated with this Connection which must be closed first.
I changed my code so each dropdown has its own reader object, own command object and own connection. I still get error. I am closing the sqlreader. Even if I comment out the first set of code I get the error on the 2nd set. If I comment out the 2nd set - the first dropdownlist populates perfectly and life is good. This is driving me nuts! Anyone see something I am doing wrong? Thanks!
Dim mySqlConnection As New SqlConnection("server=(local);Trusted_Connection=yes;database=localstuff")
mySqlConnection.open()
Dim mySqlConnection2 As New SqlConnection("server=(local);Trusted_Connection=yes;database=localstuff")
mySqlConnection2.open()
Dim objCommand As New SqlCommand("select cityname,cityid from locations order by cityname", mySqlConnection)
Dim sqlReader = objCommand.ExecuteReader()
cityNames.DataSource = sqlReader
cityNames.DataTextField = "cityname"
cityNames.DataValueField = "cityid"
cityNames.databind()
sqlreader.close()
objcommand = nothing
mySqlConnection.close()
Dim objCommand2 As New SqlCommand("select * from churchcategories order by churchcategory", mySqlConnection2)
Dim sqlReader2 = objCommand2.ExecuteReader()
sqlreader2 = objcommand2.executereader()
cbochurchcategories.DataSource = sqlReader2
cbochurchcategories.DataTextField = "churchcategory"
cbochurchcategories.DataValueField = "churchcategoryid"
cbochurchcategories.databind()
sqlreader2.close
mySqlConnection2.close()