• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

from 2003 to 2005: FormBorderStyle is gone + Assigning nothing to a SQLDataReader

1.   Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
 Me.FormBorderStyle = FormBorderStyle.None

Variable 'myReader' is used before it has been assigned a value. A null reference exception could result at runtime.
Private Sub RefreshListview

      Dim myreader As SqlDataReader
                myreader = mySqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
                Do While (myreader.Read()) = True

            Catch ex As Exception
                If Not myreader Is Nothing Then
                End If
            End Try
end sub

1 Solution

The errors you are seeing are predictive, and not absolute. If you turn off "treat warnings as errors" the code will run just fine. They are applying a very restrictive set of rules that help to make code more efficient (in most cases).

1) You can alter your code, so that it does not generate this warning/error by doing the following :

 Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

Basically, you are fully qualifying the property.

2) Having the most restrictive options on requires you to initialize a variable to a value (even if it is null, nothing, " ", etc), OR to have it explicitly assigned a value. You can alter your code so that it does not generate this warning/error by doing the following :

Dim myreader As SqlDataReader = nothing

Here you are ensuring the variable has a default value (explicitly).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now