Solved

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

Posted on 2006-07-07
1
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

628 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