Solved

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

Posted on 2004-04-20
2
227 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
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…

820 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