Returning the Display name from a drop down list box - InfoPath Dev
in

InfoPath Dev

Returning the Display name from a drop down list box

Last post 10-13-2009 04:27 PM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-13-2009 06:08 AM

    Returning the Display name from a drop down list box

    Here is my code.  It is erroring on the line in bold and I don't know why.  My Value is being properly returned as the value in my listbox.  I cannot return the Display Name.

     

    Dim root As XPathNavigator = DataSources("v_WHAllEmpsBlueBook").CreateNavigator()

    Dim iter As XPathNodeIterator = root.Select("//dfs:myFields/dfs:dataFields/d:v_WHAllEmpsBlueBook/d:EmpAssistants/@AssignID", NamespaceManager)

    Dim sb As New System.Text.StringBuilder

    Dim value As String

    Dim strValue As String

    While (iter.MoveNext())

    value = iter.Current.Value

    strValue = root.SelectSingleNode(
    "//dfs:myFields/dfs:dataFields/d:v_WHAllEmpsBlueBook/d:EmpAssistants/@AssignID[@EmpID = '" + value + "']/@FullNameLast", NamespaceManager).Value

    End While

    Filed under:
  • 10-13-2009 06:21 AM In reply to

    Re: Returning the Display name from a drop down list box

     This part of your XPath:

     ...@AssignID[@EmpID = '" + value + "']/@FullNameLast

    reads as "retrieve the FullNameLast attribute belonging to the AssignID attribute that has an EmpID attribute with the value value," but it's not possible for attributes to possess other attributes, so that is part of your problem.  My guess is you want something like

     ...d:EmpAssistants[@EmpID = '" + value + "']/@FullNameLast

     Also, unless you're absolutely sure that your .SelectSingleNode() is always going to find a match, you shouldn't reference its .Value without first checking that it's not null (or Nothing in VB speak).  If it is, you're going to wind up with null reference exceptions.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-13-2009 06:38 AM In reply to

    Re: Returning the Display name from a drop down list box

    I changed my code to look like your sample above and I am receiving the error "Object reference not set to an instance of an object.".  The variable Value contains my @EmpID value and @FullNameLast also has a value.  Why am I getting this error?

    Dim root As XPathNavigator = DataSources("v_WHAllEmpsBlueBook").CreateNavigator()

    Dim iter As XPathNodeIterator = root.Select("//dfs:myFields/dfs:dataFields/d:v_WHAllEmpsBlueBook/d:EmpAssistants/@AssignID", NamespaceManager)

    Dim sb As New System.Text.StringBuilder

    Dim value As String

    Dim strValue As String

    While (iter.MoveNext())

    value = iter.Current.Value

    strValue = root.SelectSingleNode(
    "//dfs:myFields/dfs:dataFields/d:v_WHAllEmpsBlueBook/d:EmpAssistants[@EmpID = '" + value + "']/@FullNameLast", NamespaceManager).Value

    End While

  • 10-13-2009 04:27 PM In reply to

    Re: Returning the Display name from a drop down list box

     Like I already said, unless for every AssignID value in the table, there is a row with an EmpID that has that value, that code is going to cause an "Object reference not set to an instance of an object." error.

    I can't really tell what that code is trying to accomplish.  Could you explain a bit what you are trying to do?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.