R
Rod
Thanks in advance.
I have two listboxes on a single asp page. I am trying to
use sqldatareader to populate both using two seperate sql
stored procs. I can populate each box seperately using
two different methods but when I try to populate them both
no the same page I get "InvalidOperationException: Invalid
attempt to FieldCount when reader is closed"
WHY???
Here is the code on the VB code behind page:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'pop1()
'pop2()
End Sub
Private Sub pop1()
Dim cnstr As String = "serverinfo is here"
Dim cn As New SqlConnection()
Dim cmd As New SqlCommand()
cn.ConnectionString = cnstr
Try
'*******Populate the Info Packets
'Set up Stored Proc
cmd.CommandText = "LookupFind"
cmd.CommandType() = CommandType.StoredProcedure
cmd.Connection = cn
'Pass Parameters
cmd.Parameters.Add("@LookupType", "Info")
'Execute
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
chkInfo().DataSource = dr
chkInfo().DataTextField = "LookupDesc"
chkInfo().DataValueField = "pkLookupId"
DataBind()
'Cleanup
dr.Close()
Catch
'Throw the previous exception to the caller
Throw
Finally
'Dispose is used in place of close
'Close is called by dispose
cn.Dispose()
cn = Nothing
End Try
End Sub
Private Sub pop2()
Dim cnstr As String = "serverinfo is here"
Dim cn As New SqlConnection()
Dim cmd As New SqlCommand()
cn.ConnectionString = cnstr
Try
'*******Populate the Info Packets
'Set up Stored Proc
cmd.CommandText = "ResortFill"
cmd.CommandType() = CommandType.StoredProcedure
cmd.Connection = cn
'Pass Parameters
'cmd.Parameters.Clear()
'Execute
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
chkResort().DataSource = dr
chkResort().DataTextField = "ResortName"
chkResort().DataValueField = "pkResortId"
DataBind()
'Cleanup
dr.Close()
Catch
'Throw the previous exception to the caller
Throw
Finally
'Dispose is used in place of close
'Close is called by dispose
cn.Dispose()
cn = Nothing
End Try
End Sub
I have two listboxes on a single asp page. I am trying to
use sqldatareader to populate both using two seperate sql
stored procs. I can populate each box seperately using
two different methods but when I try to populate them both
no the same page I get "InvalidOperationException: Invalid
attempt to FieldCount when reader is closed"
WHY???
Here is the code on the VB code behind page:
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'pop1()
'pop2()
End Sub
Private Sub pop1()
Dim cnstr As String = "serverinfo is here"
Dim cn As New SqlConnection()
Dim cmd As New SqlCommand()
cn.ConnectionString = cnstr
Try
'*******Populate the Info Packets
'Set up Stored Proc
cmd.CommandText = "LookupFind"
cmd.CommandType() = CommandType.StoredProcedure
cmd.Connection = cn
'Pass Parameters
cmd.Parameters.Add("@LookupType", "Info")
'Execute
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
chkInfo().DataSource = dr
chkInfo().DataTextField = "LookupDesc"
chkInfo().DataValueField = "pkLookupId"
DataBind()
'Cleanup
dr.Close()
Catch
'Throw the previous exception to the caller
Throw
Finally
'Dispose is used in place of close
'Close is called by dispose
cn.Dispose()
cn = Nothing
End Try
End Sub
Private Sub pop2()
Dim cnstr As String = "serverinfo is here"
Dim cn As New SqlConnection()
Dim cmd As New SqlCommand()
cn.ConnectionString = cnstr
Try
'*******Populate the Info Packets
'Set up Stored Proc
cmd.CommandText = "ResortFill"
cmd.CommandType() = CommandType.StoredProcedure
cmd.Connection = cn
'Pass Parameters
'cmd.Parameters.Clear()
'Execute
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
chkResort().DataSource = dr
chkResort().DataTextField = "ResortName"
chkResort().DataValueField = "pkResortId"
DataBind()
'Cleanup
dr.Close()
Catch
'Throw the previous exception to the caller
Throw
Finally
'Dispose is used in place of close
'Close is called by dispose
cn.Dispose()
cn = Nothing
End Try
End Sub