<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>query &amp; check if node was returned</title><link>https://www.infopathdev.com:443/forums/thread/12596.aspx</link><pubDate>Fri, 30 Sep 2005 16:18:55 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:12596</guid><dc:creator>nkelkar</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/12596.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=12596</wfw:commentRss><description>This is a vb.net managed code. I am getting an error "Object Reference not Set" at Line 14 where I compare if cNode is Nothing.&lt;br /&gt;&lt;br /&gt;What this Sub does is it takes the query parameter RCTID and does a thisXDocument.Query(), after which I want to see (compare) if a node was returned or not. If a valid node was returned then alls ok (do not prompt), else prompt "ID not found in the database". I have trimmed down this code, because there is additional processing I would like to do after this, but have to resolve this issue before proceeding ahead.&lt;br /&gt;&lt;br /&gt;There exists an RCTID=3 in the database, I enter 3 on the query parameter RCTID within the infopath form, hit the BTN_SEARCH button, and infopath returns all data related to RCTID=3, but it also complains "Object Reference not set" at Line 14.&lt;br /&gt;&lt;br /&gt;If returned then I am assuming cNode should not be empty, but it always gives an error, no matter if a node is retrieved or not.&lt;br /&gt;&lt;br /&gt;Any ideas why?&lt;br /&gt;&lt;br /&gt; 1 &amp;lt;InfoPathEventHandler(MatchPath:="BTN_SEARCH",EventType:=InfoPathEventType.OnClick)&amp;gt; _&lt;br /&gt; 2 Public Sub BTN_SEARCH_OnClick(ByVal e As DocActionEvent)&lt;br /&gt; 3     ' Write your code here.&lt;br /&gt; 4     Try&lt;br /&gt; 5  Dim qcurrRCTID =thisXDocument.DOM.selectSingleNode("//q:Main").attributes.getNamedItem("RCTID").text&lt;br /&gt; 7  If (qcurrRCTID = String.Empty) Then&lt;br /&gt; 8      Throw New Exception("Please enter a Transfer #")&lt;br /&gt; 9  ElseIf (Integer.Parse(qcurrRCTID) &amp;lt;= 0) Then&lt;br /&gt;10      Throw New Exception("Please enter a Numeric ID")&lt;br /&gt;11  Else&lt;br /&gt;12      thisXDocument.Query()&lt;br /&gt;13      Dim cNode As IXMLDOMNode =thisXDocument.DOM.selectSingleNode("//d:Main/")&lt;br /&gt;14      If cNode Is Nothing Then&lt;br /&gt;15   Throw New Exception("ID not found in thedatabase")&lt;br /&gt;16      End If&lt;br /&gt;17  End If&lt;br /&gt;18     Catch eX As Exception&lt;br /&gt;19  thisXDocument.UI.Alert(eX.Message)&lt;br /&gt;20     End Try&lt;br /&gt;21 End Sub&lt;br /&gt;</description></item></channel></rss>