|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Testing for OleDbDataReader is nothing before closing itDim dr1 As OleDbDataReader .....Code here If Not dr1 Is Nothing Then If Not dr1.IsClosed Then dr1.Close() end if End Try However in VB2005 I get the (correct) error message dr1 is used before it has been assigned a value. A Null reference exception could result at run time. What syntax should I be using now? Thanks -Jerry You have 2 options
1. set this naging warning off 2. always assign default values in the case of a object without a constructor assign Nothing Dim dr As OleDb.OleDbDataReader = Nothing otherwise just construct the object ( foo As New .......) regards Michel Posseth [MCP] Show quoteHide quote "Jerry Spence1" wrote: > I have been doing the following is VB.Net 2003: > > Dim dr1 As OleDbDataReader > > > .....Code here > > > > If Not dr1 Is Nothing Then > > If Not dr1.IsClosed Then > dr1.Close() > end if > > End Try > > > However in VB2005 I get the (correct) error message > > dr1 is used before it has been assigned a value. A Null reference exception > could result at run time. > > What syntax should I be using now? > > Thanks > > -Jerry > > >
Is microsoft awaring VB.Net too hard to maintain?
Class used by multiple threads to write to Table Override Printer Margins (?) text/xml reporting service error Opacity on form Visual Studio .NET 2005 using Web Application Project Retrieving the System date and time settings WEB ENABLING a win application: best approach Creating an array of objects when the object type is not known at design time SQL update statment, using ACCESS yes/no |
|||||||||||||||||||||||