Solved

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

Posted on 2006-07-07
1
262 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
Comment Utility

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

6 Experts available now in Live!

Get 1:1 Help Now