That's the way the code was initially when the select statements
were in the page, which worked. I did try your suggestion.
I am now getting an error "myDataReader" is not declared
On line 58 after the Finally.
Here's where I'm at now. Any pointers would be appreciated
Thanks again

Sub Page_Load(sender As Object, e As EventArgs) 
        
        Dim myConnection As SqlConnection = new SqlConnection
(ConfigurationSettings.AppSettings("SQLServerConnection"))

        If Not Page.IsPostBack Then             
          Dim myCommand As SqlCommand = new SqlCommand("proc_clname", 
myConnection)
        
          Dim myDataReader As SqlDataReader

          Try
            myConnection.Open()

            myDataReader = myCommand.ExecuteReader
(CommandBehavior.CloseConnection)

            myDropDownList.DataSource = myDataReader
            myDropDownList.DataBind()
          Catch myException As Exception
            Response.Write("An error has occurred: " & 
myException.ToString())
          Finally
            If Not myDataReader Is Nothing Then
              myDataReader.Close()
             End If
                
             myDropDownList.Items.Insert(0, "Select an Item")
             myDropDownList.SelectedIndex = 0
          End Try
        End If  

        'We don't want this code to run when the default item is 
selected
        If Not myDropDownList.SelectedIndex = 0 Then
          myDataGrid.Visible = true

          
          
          Try
          Dim myConnection2 As SqlConnection = new SqlConnection
(ConfigurationSettings.AppSettings("SQLServerConnection"))
       myConnection2.Open()
          
          Dim myCommand As SqlCommand = new SqlCommand("proc_selDesc")
myCommand.Connection=myConnection2
 Dim myDataReader As SQLClient.SqlDataReader= myCommand.ExecuteReader
(CommandBehavior.CloseConnection)

            myDataGrid.DataSource = myDataReader
            myDataGrid.DataBind()
          Catch myException As Exception
            Response.Write("An error has occurred: " & 
myException.ToString())
          Finally
            If Not myDataReader Is Nothing Then [FAILS HERE]
              myDataReader.Close()
            End If
          End Try
        Else
          myDataGrid.Visible = false
        End If

 End Sub
</script>
 










--- In [email protected], Dean Fiala 
<[EMAIL PROTECTED]> wrote:
> You don't have a connection when you call
> 
> Dim myCommand As SqlCommand = new SqlCommand("proc_selDesc", 
myConnection)
> 
> Because you don't open it until two lines later
> 
> myConnection.Open()
> 
> Open the connection first and you'll be fine
> 
> 
> On Mon, 20 Dec 2004 04:42:24 -0000, ltrane923 <[EMAIL PROTECTED]> 
wrote:
> > 
> > 
> > Thanks for responding. I have posted all my code here.
> > 
> > http://www.loritompkins.com/sqlnop/code.html
> > 
> > There is something wrong with the way I am making this second
> > connection. Maybe it needs to be converted to a string? I can't 
seem
> > to figure it out.
> > 
> > The only thing I changed where the lines in red.
> > They were formerly select statements
> > 
> > FROM THIS (second statement)
> >  Dim myCommand As SqlCommand = new SqlCommand("Select * From
> > dbo.tbltopicDesc  Where topicID='" & 
myDropDownList.SelectedItem.Value
> > & "'",myConnection)
> > 
> > To this
> > Dim myCommand As SqlCommand = new SqlCommand("proc_clname",
> > myConnection)
> > 
> > Here it is working with all select statements
> > http://www.loritompkins.com/sqlnop/pulldowngrid2.aspx
> > 
> > Here it fails [no data paints to the grid from reader]
> > http://www.loritompkins.com/sqlnop/pulldowngrid6.aspx
> > 
> > --- In [email protected], Dean Fiala 
<[EMAIL PROTECTED]>
> > wrote:
> > > According to the code in your link, the DataReader is closed 
after
> > the
> > > reader is executed...
> > >
> > > myDataReader = myCommand.ExecuteReader(CommandBe
> > havior.CloseConnection)
> > >
> > > Are you sure you are calling myConnection.Open() again
> > >  before calling this code...
> > >
> > >   Dim myCommand As SqlCommand = new
> > > SqlCommand("secondstoredprocedure", myConnection) [this fails]
> > >
> > > HTH
> > > --
> > > Dean Fiala
> > > Very Practical Software, Inc
> > > http://www.vpsw.com
> > 
> > 
> > Yahoo! Groups Links
> > 
> > 
> > 
> > 
> > 
> 
> 
> -- 
> Dean Fiala
> Very Practical Software, Inc
> http://www.vpsw.com





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to