Node is null? What? I just put something in there! - InfoPath Dev
in

InfoPath Dev

Node is null? What? I just put something in there!

Last post 02-12-2015 11:09 AM by Hilary Stoupa. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 02-12-2015 08:47 AM

    Node is null? What? I just put something in there!

     Greetings all, I have had the greatest headache overcoming this problem! I am new to C# and XML. I have an InfoPath 2013 form that gets it data from a SQL table through a data connection. I need to filter the data using wildcards. I have been following Microsoft's directions to accomplish this (http://support.microsoft.com/kb/826992). I made the custom changes to suit my needs and I have followed the code letter for letter. but when I run the code, it crashes right where I enter the text to use in the query. The error message I get is "NullReferenceException was unhandled by user code : Object reference not set to an instance of an object." I have been beating my head against the wall trying to figure this one out. I have searched extensively but nothing is helping. Here is the offending line:

    string strPart_ID = xnSuppliersQuery.SelectSingleNode("@Part_ID", this.NamespaceManager).Value;

    This is where I grab the value that was entered by the user, assign to a var so I can use it. It seems to not be able to see that I have entered a value and tells me that the node is null. Any help would be greatly appreciated! Screenshot below:

     

    Wakgtech

     






  • 02-12-2015 08:51 AM In reply to

    Re: Node is null? What? I just put something in there!

    I can't see your screenshot - can you post more of your code? Maybe a screenshot of the schema in question? You can attach your screenshot under the Options tab in a reply.

    Hilary Stoupa

  • 02-12-2015 08:59 AM In reply to

    Re: Node is null? What? I just put something in there!

     Here is the screenshot. Offending line is highlighted.

     

    thanks!

     

    wakgtech 


  • 02-12-2015 09:03 AM In reply to

    Re: Node is null? What? I just put something in there!

    So, your form is bound to a SQL DB? If you go to the fields task pane, and right click the query field PART_DIMENSION and select copy XPath, what is the resulting XPath? I'm thinking your XPath Navigator xnSuppliersQuery is null. Do you know how to run your code in debug? If not, I have a blog post that may help you - http://www.infopathdev.com/blogs/hilary/archive/2009/09/27/debug-managed-code-in-vsta-for-the-accidental-programmer.aspx

    Hilary Stoupa

  • 02-12-2015 09:53 AM In reply to

    Re: Node is null? What? I just put something in there!

     This is my resulting XPath "/dfs:myFields/dfs:queryFields/q:PART_DIMENSION" is this not correct? I will now look at your blog post! Thanks for your assistance!

  • 02-12-2015 10:03 AM In reply to

    Re: Node is null? What? I just put something in there!

    xnMain.SelectSingleNode is not using that XPath tho, right? :)

    Edited to add the line of code, I was being lazy -

    XPathNavigator xnSuppliersQuery = xnMain.SelectSingleNode(""/dfs:myFields/dfs:queryFields/q:PART_DIMENSION", this.NamespaceManager);

    Hilary Stoupa

  • 02-12-2015 10:10 AM In reply to

    Re: Node is null? What? I just put something in there!

     OK, I did find that I had to change my code for the var xnSuppliersQuery. But it still hangs at the same place.

     

    Bill 


  • 02-12-2015 10:21 AM In reply to

    Re: Node is null? What? I just put something in there!

    Hover your cursor over xnSuppliersQuery - is it null? If not, what is the full XPath to the field you are trying to set the value of?

    Hilary Stoupa

  • 02-12-2015 10:32 AM In reply to

    Re: Node is null? What? I just put something in there!

    when I hover over xnSuppliersQuery, it is NOT null. I am thinking the full xpath is




    "/dfs:myFields/dfs:queryFields/q:PART_DIMENSION/:Part_ID)

     

     

  • 02-12-2015 10:41 AM In reply to

    Re: Node is null? What? I just put something in there!

     I turned on a few watches and this is what I got. Any Ideas?


  • 02-12-2015 10:46 AM In reply to

    Re: Node is null? What? I just put something in there!

    You just have a : before Part_ID - there would be something before that- just right click the query field and copy the XPath - paste it in a reply.

    Hilary Stoupa

  • 02-12-2015 10:53 AM In reply to

    Re: Node is null? What? I just put something in there!

     /dfs:myFields/dfs:queryFields/q:PART_DIMENSION/@PART_ID

    That was it!!!!!!!!!!!!! Problem solved. You are a Goddess! Thank You very much! This has been a stickler of a problem here and this will make me look very good! Thank you so much. If you have written any books, send me some links!

     

    WAKGTECH
    (another thankful customer) 

  • 02-12-2015 11:09 AM In reply to

    Re: Node is null? What? I just put something in there!

    XPath is case sensitive - gotta watch those caps! Glad you solved it - you'll sleep well tonight.

    Isn't it fun when you bend the computer to your will?

    Hilary Stoupa

Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.