473,324 Members | 2,254 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,324 software developers and data experts.

Question: How check if datareader is null?

Hi

Try this:
finally
' Always call Close when done reading.
if Not (myDataReader is Nothing)
myDataReader.Close()
end if

Ravikanth[MVP]

-----Original Message-----
I have a datareader that I use in my Try block. In the Finally I want toclose the datareader, but ONLY if it is not null/nothing. How can I dothis?

I've tried these already...
If drReader <> Nothing Then...
If drReader Is Not Null Then...
If drReader Is Not System.DbNull Then...

None work. Ideas?

Thanks!
.

Nov 17 '05 #1
1 1993
Thanks Ravikanth!

"Ravikanth[MVP]" <dv*********@hotmail.com> wrote in message
news:0d****************************@phx.gbl...
Hi

Try this:
finally
' Always call Close when done reading.
if Not (myDataReader is Nothing)
myDataReader.Close()
end if

Ravikanth[MVP]

-----Original Message-----
I have a datareader that I use in my Try block. In the

Finally I want to
close the datareader, but ONLY if it is not

null/nothing. How can I do
this?

I've tried these already...
If drReader <> Nothing Then...
If drReader Is Not Null Then...
If drReader Is Not System.DbNull Then...

None work. Ideas?

Thanks!
.

Nov 17 '05 #2

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

Similar topics

5
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! When reading a value from an SQL database i get to a DateTime variable... How can i check that the there is no value assigned? Since i cant use if(myDate.ShortDate != null) ? Regards
5
by: Gelios | last post by:
Hello All! I am going to crazy and feeling myself so stupid but I don't understand such behaviour. I have code: public int getNextAgentId() { Int32 agent_id = 0; IDataReader dr =...
2
by: Mike P | last post by:
I have the following code in my Page_Load event to populate a listbox from a database : if (!(Page.IsPostBack)) { SqlConnection objConnection = new...
1
by: Mike P | last post by:
I'm using 1 connection to open 3 separate data readers to read data into 3 data grids. However, when I try to use the 2nd reader it says that the first reader must be closed. So I use Close() to...
2
by: Martin Raychev | last post by:
Hi all, I have the following problem: I have a private method that returns a SqlDataReader. For this to work I have not to close the DB connection in the above method. I do this only to
3
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr...
0
by: Jet Mah | last post by:
Hi, Mert I want to update the "read_status" colum when reading data, this is my way as below: //...
2
by: =?Utf-8?B?ZGJhMTIz?= | last post by:
Note, I'm using C# I am wondering what type of control I should use for iterating through the set of records returned by callin this method below, so that I can then do some stuff with each...
1
by: =?UTF-8?B?QXJuZSBWYWpow7hq?= | last post by:
JB wrote: if(!reader.IsDBNull(swimcol)) { // use (string)reader } else { // use some default value maybe null
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.