开发者

BC3016: Variable 'myConnection' hides a variable in an enclosing block

开发者 https://www.devze.com 2023-01-07 21:27 出处:网络
I\'m am not quite sure why I am getting this error. Dim numUsers as Integer Using myConnection as New System.Data.SqlClient.SqlConnection(\"Data Source=(local);InitialCatalog=dbtest;Integrated Securi

I'm am not quite sure why I am getting this error.

Dim numUsers as Integer
Using myConnection as New System.Data.SqlClient.SqlConnection("Data Source=(local);InitialCatalog=dbtest;Integrated Security=True")
   Dim queryString As String = "SELECT COUNT(*) AS Num_Of_User F开发者_如何学JAVAROM tblusers WHERE username=@username AND password=@password"
   Using myCommand as New System.Data.SqlClient.SqlCommand(queryString, myConnection)
      myConnection.Open
      myCommand.Parameters.AddWithValue("@username", requestName)
      myCommand.Parameters.AddWithValue("@password", requestPass) 
      numUsers = myCommand.ExecuteScalar()
   End Using
End Using 

This error occurs on the first using statment. Can anyone help resolve this?


the variable myConnection is declared at a higher level of scope above the Using statement. The Using statement is trying to create myConnection with the scope of the Using block but that would conflict with myConnection which has scope above that.

0

精彩评论

暂无评论...
验证码 换一张
取 消