[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?
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?
Re: "Variable 'cnn' hides a variable in an enclosing block