?
Solved

if No Record found, datareader giving Error Message

Posted on 2004-09-27
7
Medium Priority
?
499 Views
Last Modified: 2007-12-19
Sir

For some purpose, I used datareader.  It is giving error messages, if no records avaialble.  In this case, any property or method is available to know datareader is blank.  Like record count or eof ......

Please help me
0
Comment
Question by:adwat
[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
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
KGreg earned 672 total points
ID: 12163556
do this:


while objReader.Read

     ' Loop through records.. objReader will be on the current record and this loop will execute as long as there is a record

End while


or if you're expecting a single record:

if objReader.read then
   ' Work on that one record then close the reader..
else

     '  No records.

end if


KGREG
0
 
LVL 6

Expert Comment

by:KGreg
ID: 12163581
NOTE:

calling objReader.Read puts the objReader on the next record.  Initially, there is no current record.. so you need to call this to get to the first record.

The read function returns a boolean - True if there is a Next record.. and false if there is not.


KGREG
0
 
LVL 8

Assisted Solution

by:wguerram
wguerram earned 664 total points
ID: 12164866
You can also use HasRows property

if MyDataread.d.HasRows then
    MyDataread.Read
end if
0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 664 total points
ID: 12165505
You can do this :

Dim SqlDataReadr As SqlDataReader = SqlCommand1.ExecuteReader()
If SqlReader Is Nothing Then
   'No record to read
   Exit Sub
End If

-Baan
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

764 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