473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Testing for OleDbDataReader is nothing before closing it

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
Jul 4 '06 #1
1 1470
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]
"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
Jul 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dion Heskett | last post by:
I wish to supply the formating as a parameter, I have tried OleDbDataReader but get a null ref. just can't seem to get this to work. I think this has something to do with ExecuteReader. also...
7
by: Smitty | last post by:
I have a function that imports an Excel file into an Access table using SQL. I then close the OleDataReader and the OleDbConnection, then dispose the OleDbCommand, then OleDbConnection. The calling...
0
by: Steve1 via DotNetMonster.com | last post by:
Hi all, I''ve created an OleDbDataReader that will contain the number of records that the used SQL query will return. I'm then using a while loop to loop while the OleDBDataReader object has...
2
by: Grant | last post by:
Why wont this SQL query work? I am connecting to an Access database and when using 'mySelectQuery1' it returns a datareader but when using 'mySelectQuery2' it returns nothing...I can run this query...
1
by: Keith | last post by:
Hi, if have this method in a cs file that connections to a database and returns a datareader to my web form. public OleDbDataReader GetDataReader(string theSQL) { theConn = new...
1
by: Steven K | last post by:
Hello, I am using the following code which works. My question is does the OleDbDataReader need to be closed and then re-executed for every control? Is there a more effecient way of doing this...
0
by: hmcclungiii | last post by:
I've tried GetInt16, GetInt32, GetInt64, nothing works. I've even tried to retrieve the value as a string and use cInt and Val to convert it back. No matter what I do, it just doesn't want to get...
1
by: Mel | last post by:
I am performing the same recordset multiple times, just passing different parameters each time. Is there a way to do this more efficiently without having to close and re-open the connection and...
7
by: andreas | last post by:
Can someone tell me 1) Is there a difference between closing or disposing a reference data type 2) about nothing dim fr as form2 isnothing(fr) gives true
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.