troubleshooting Question

Databind with Stored Procedures

Avatar of alexcryout
alexcryoutFlag for United States of America asked on
ASP.NETVisual Basic.NET
4 Comments1 Solution320 ViewsLast Modified:
Hi Experts,

I use one Stored Procedures to fill two dropdown list boxes:

Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("GetCodes", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

Try
   myConnection.Open()
   Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
   Return result
Catch Ex As Exception
   Return Nothing
End Try

And my databind is:
Dim SNs As SqlDataReader = CodesDB.GetAvailableCodes()

dlstSN.DataSource = SNs
dlstSN.DataTextField = "SN"
dlstSN.DataValueField = "ID"
dlstSN.DataBind()
 
dlstCodes.DataSource = SNs
dlstCodes.DataTextField = "Code"
dlstCodes.DataValueField = "ID"
dlstCodes.DataBind()

Then I got the "Invalid attempt to call FieldCount when reader is closed." error on the second databind.

Please help.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros