?
Solved

if No Record found, datareader giving Error Message

Posted on 2004-09-27
7
Medium Priority
?
500 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 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