query & check if node was returned

N

NK

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.

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.

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.

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.

Any ideas why?

1
<InfoPathEventHandler(MatchPath:="BTN_SEARCH",EventType:=InfoPathEventType.OnClick)>
_
2 Public Sub BTN_SEARCH_OnClick(ByVal e As DocActionEvent)
3 ' Write your code here.
4 Try
5 Dim qcurrRCTID
=thisXDocument.DOM.selectSingleNode("//q:Main").attributes.getNamedItem("RCTID").text
7 If (qcurrRCTID = String.Empty) Then
8 Throw New Exception("Please enter a Transfer #")
9 ElseIf (Integer.Parse(qcurrRCTID) <= 0) Then
10 Throw New Exception("Please enter a Numeric ID")
11 Else
12 thisXDocument.Query()
13 Dim cNode As IXMLDOMNode
=thisXDocument.DOM.selectSingleNode("//d:Main/")
14 If cNode Is Nothing Then
15 Throw New Exception("ID not found in thedatabase")
16 End If
17 End If
18 Catch eX As Exception
19 thisXDocument.UI.Alert(eX.Message)
20 End Try
21 End Sub
 
F

Franck Dauché

Hi,

Have you tried to remove the final "/"? Also, is your prefix d or q?

Franck Dauché
 
N

NK

Sorry, In the first post Line #13 should read as:

13 Dim cNode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("//d:Main")

So I cranked up the debugger, and as the form was executing I watched
"cNode", well guess what the cNode contains the correct xml structure
including data.

To search the system, prefix is "q" as we are searching a parameter
from the query, when the query is executed, results are in the
parameter "d", and I am checking if //d:Main contains anything.

It is working correctly now.

Thanks,
NK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top