Solved

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

631 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