Solved

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

Posted on 2006-07-07
1
266 Views
Last Modified: 2012-08-14
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

2.
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
            Try
                mySqlConnection.Open()
                myreader = mySqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
                Do While (myreader.Read()) = True
                   ListView1.Items.Add(myreader("no").ToString())
                Loop

            Catch ex As Exception
                 
            Finally
                If Not myreader Is Nothing Then
                    myreader.Close()
                    mySqlConnection.Close()
                End If
            End Try
end sub


0
Comment
Question by:jxharding
1 Comment
 
LVL 8

Accepted Solution

by:
Shakti109 earned 500 total points
ID: 17057798

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).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question