Solved

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

Posted on 2006-07-07
1
263 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protecting vb6 & .Net code Obfuscation 18 97
Close word object 13 38
fso.FolderExists("\\server\HiddenFolder$") 4 52
Help with LINQ and XML 10 27
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now