Programmatically Query Secondary Data Connections

K

Kalpana

Hi All

I have used this code in Infopath 2003 and it would work ok but when i use
the same in Infopath 2007 and if it doesn't retrieve a result it throws an
error - "Object reference not set"

If the currentuser exists in the list, it works fine.

XPathNavigator xnBS = this.DataSources["Billing
Specialist"].CreateNavigator();
string myRole = string.Empty;
myRole =
xnBS.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Billing_Specialist/@BillingSpecialistEmail[../@Billing_Specialist_UserID
= '" + currentUser + "']", this.NamespaceManager).Value;

Any ideas?

Thanks for you help
 
G

Gavin McKay

Hello,

Might be a change in how the SelectSingleNode works with IP2007. It uses a
different XML processor version from memory (sorry can't remember version
numbers :) so it is possible that IP2003 would return (for example) a blank
string, whereas IP2007 returns null as the result of the SelectSingleNode and
therefore errors out with "Object reference not set" when you try and access
the .Value property.

You might need to create an object that will accept the results of
SelectSingleNode, and then test if it is valid before accessing the .Value
property similar to the following:

XPathNavigator xnBS = this.DataSources["Billing
Specialist"].CreateNavigator();
string myRole = string.Empty;
object myRoleNode =
xnBS.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Billing_Specialist/@BillingSpecialistEmail[../@Billing_Specialist_UserID
= '" + currentUser + "']", this.NamespaceManager);
if (myRoleNode!=null)
{
myRole = myRoleNode.Value;
}

HTH

Gavin.
 
K

Kalpana

Thanks - that's what i did and it worked

Gavin McKay said:
Hello,

Might be a change in how the SelectSingleNode works with IP2007. It uses a
different XML processor version from memory (sorry can't remember version
numbers :) so it is possible that IP2003 would return (for example) a blank
string, whereas IP2007 returns null as the result of the SelectSingleNode and
therefore errors out with "Object reference not set" when you try and access
the .Value property.

You might need to create an object that will accept the results of
SelectSingleNode, and then test if it is valid before accessing the .Value
property similar to the following:

XPathNavigator xnBS = this.DataSources["Billing
Specialist"].CreateNavigator();
string myRole = string.Empty;
object myRoleNode =
xnBS.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Billing_Specialist/@BillingSpecialistEmail[../@Billing_Specialist_UserID
= '" + currentUser + "']", this.NamespaceManager);
if (myRoleNode!=null)
{
myRole = myRoleNode.Value;
}

HTH

Gavin.

Kalpana said:
Hi All

I have used this code in Infopath 2003 and it would work ok but when i use
the same in Infopath 2007 and if it doesn't retrieve a result it throws an
error - "Object reference not set"

If the currentuser exists in the list, it works fine.

XPathNavigator xnBS = this.DataSources["Billing
Specialist"].CreateNavigator();
string myRole = string.Empty;
myRole =
xnBS.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Billing_Specialist/@BillingSpecialistEmail[../@Billing_Specialist_UserID
= '" + currentUser + "']", this.NamespaceManager).Value;

Any ideas?

Thanks for you help
 

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