Solved

How do I avoid the Object reference not set error when ExecuteXmlReader has no records?

Posted on 2004-04-20
2
211 Views
Last Modified: 2008-03-10
If have a SQL Server 2000 stored procedure that returns xml using "for xml auto" and also returns a return value.  If I use ExecuteXmlReader, I get an "Object reference not set to an instance of an object" error when there are no records that meet the criteria in my stored procedure because no xml is returned.  Is there anyway to avoid this error?
0
Comment
Question by:RODEhard
2 Comments
 
LVL 5

Accepted Solution

by:
chaniewskim earned 250 total points
ID: 10870981
I use a SqlDataReader and build an XML string using StringBuilder. With that method you can check if your query returned any data using reader.HasRows
0
 

Expert Comment

by:FouadDaniels
ID: 10897930
Would not it be better to have your SP send 1 node with "Empty" node in it and test at the client if the XML contains anyth8ing other then an "Empty" node.
That way you know it has data and it will never fail. I would gues that would be much faster in your scenario.

Regards,
Fouad
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now