Results 1 to 3 of 3

Thread: [RESOLVED] "Variable 'cnn' hides a variable in an enclosing block

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Resolved [RESOLVED] "Variable 'cnn' hides a variable in an enclosing block

    Hi!

    I have the following code but I get blue squiggly line in cnn and when i point my mouse pointer on it i see this message "Variable 'cnn' hides a variable in an enclosing block"
    Code:
      Private Sub BtnLockUnlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLockUnlock.Click
            Dim IsLocked As Boolean = FpSpread1.ActiveSheet.DefaultStyle.Locked
            ''Dim imageIcon As String = IIf(IsLocked, "lock_icon.gif", "lock_icon_open.gif")
    
            If IsLocked = True Then
    
                FpSpread1.ActiveSheet.DefaultStyle.Locked = False
    
                Using cnn As New SqlConnection("My.Settings.ConnectionString")
                    Using cnn As New SqlCommand("UPDATE tblLockUnlock SET Locked=@Bol WHERE Period=@Per", cnn)
                        cnn.Parameters.AddWithValue("@Bol", "False")
                        cnn.Parameters.AddWithValue("@Per", "1G_HS")
                        cnn.ExecuteNonQuery()
                    End Using
                End Using
    
            Else
    
                FpSpread1.ActiveSheet.DefaultStyle.Locked = True
            
            End If
            Call LockUnlockImage()
        End Sub
    i have this on form load
    Code:
    cnn = New SqlConnection(My.Settings.ConnectionString)
    what's wrong with my code?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: "Variable 'cnn' hides a variable in an enclosing block

    You have two nested Using blocks and they both declare a variable named 'cnn'. How can 'cnn' refer to a SqlConnection and a SqlCommand?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: "Variable 'cnn' hides a variable in an enclosing block

    thanks jm!
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width