Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

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

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
RODEhard
Asked:
RODEhard
1 Solution
 
chaniewskimCommented:
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
 
FouadDanielsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now