Solved

if No Record found, datareader giving Error Message

Posted on 2004-09-27
7
498 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 168 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 166 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 166 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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