Object reference not set to an instance of an object

S

swathi

Hi,
I am trying to connect to the db from infopath form through code.I wrote the
following code.
DataSource dscustomer = this.DataSources["CustomerNextNumber"];
XPathNavigator xnCustomer = dsCustomer.CreateNavigator();
XPathNavigator CustID =
xnCustomer.SelectSingleNode("/dfs:myFields/dfs:queryFields/d:CustomerNextNumber/d:CustID", NamespaceManager);
string strCustID = CustID.Value; // Read
CustID.SetValue(strApqpNbr);

At runtime, I am getting the NullReference Exception as follows.
"Object reference not set to an instance of an object"

How to resolve this.
Thanks
 
D

David Dean

There's no way to tell for sure from your code, but the null object reference
is probably occurring on the CustID variable because of a failure in
resolving the XPath expression. This may possibly be due to a case mismatch
or to using a different namespace prefix than InfoPath is expecting.

To double-check the XPath expression, go to the Data Sources pane, select
your CustomerNextNumber data source, expand the nodes to show your CustID
field, then select the "Copy XPath" option from the field's dropdown menu.
Then paste it into your code and compare.

--
David Dean
Sr. Member Technical Staff
Insource Technology Corp.


swathi said:
sorry, in last line it is strCustID.

CustID.SetValue(strCustID);

swathi said:
Hi,
I am trying to connect to the db from infopath form through code.I wrote the
following code.
DataSource dscustomer = this.DataSources["CustomerNextNumber"];
XPathNavigator xnCustomer = dsCustomer.CreateNavigator();
XPathNavigator CustID =
xnCustomer.SelectSingleNode("/dfs:myFields/dfs:queryFields/d:CustomerNextNumber/d:CustID", NamespaceManager);
string strCustID = CustID.Value; // Read
CustID.SetValue(strApqpNbr);

At runtime, I am getting the NullReference Exception as follows.
"Object reference not set to an instance of an object"

How to resolve this.
Thanks
 

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