Solve This!... - InfoPath Dev
in

InfoPath Dev

Solve This!...

Last post 07-14-2011 02:46 PM by rhernanf. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-16-2009 11:30 AM

    Solve This!...

    Okay...whomever can help me out with this one ( a viable solution ) will forever be held in the utmost highest esteem in my mind concerning Infopath..lol

    I have a web enabled form. The form has a repeating section. In the repeating section, there is a textbox, date-picker control, and another textbox. The values of the form are written to a SQL Server database when the form is submitted.

    The values of the repeating section submit to the database just fine when there is one section. How in the blazes do I reference programmatically ( C# ) additional sections the user may create, let alone each control in the n-number of sections, so I can submit the data contained in the controls for each section?  Boy that was a mouth-full..lol.  Understand?

    Wondering....... I've seen countless articles on how to iterate through a repeating tables. Examples such as

                 XPathNavigator myNav = MainDataSource.CreateNavigator();
                XPathNodeIterator NodeIterator = myNav.Select("/my:TimeCard/my:EmployeeSection/my:ProjectSection/my:Project", NamespaceManager);//Repeating table

                XPathNavigator myNode;
                while (NodeIterator.MoveNext())  //Iterate through table
                {
                    myNode = NodeIterator.Current.CreateNavigator();
                    ProjectName = myNode.SelectSingleNode("my:ProjectName", NamespaceManager).Value;
                    HoursWorked = myNode.SelectSingleNode("my:phTotal", NamespaceManager).Value;

                    MessageBox.Show("ProjectName = " + ProjectName + "\nHoursWorked = " + HoursWorked); //NodeIterator.Current.el.Value);
                }

    So I'm wondering if I could just replace the reference to the repeating table with my repeating Section? And then get a handle to my controls in the section?... duuuuh huuuh!... lol.  Ya think?

     


     

     

     

  • 12-16-2009 09:20 PM In reply to

    this code should work for repeating section, because from xml prespective it does not distinguish between a repeating table and a repeating section. so what ever code works for repeating table navigation will work for repeating section navigation also

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 12-17-2009 10:05 AM In reply to

    Yes...one would think so, meaning it should work. However, it doesn't.  Or...I'm doing something wrong which could very well be the case.

    The form has two sections. And the XPathNodeIterator object is cycling twice as expected. ( ie...the count being 2, which is correct. However, only the data from the first section is being referenced, and thus being inserted into the database tables. So I get two rows in the database table, with each row being identical...swell!

    The code isn't erroring out, so I know my C# code that gets a handle to each control in the section is correct. It just dosen't seem to advance. The XPathNodeIterator object that is.

    My code

     XPathNavigator myNav = MainDataSource.CreateNavigator();
     XPathNodeIterator NodeIterator = myNav.Select("/my:myFields/my:commentsResponseSection", NamespaceManager);  //Repeating section

      while (NodeIterator.MoveNext())  //Iterate through sections
                {
                    string sComment =   NodeIterator.Current.SelectSingleNode("//my:Comment", NamespaceManager).Value;
                    string sResponse =   NodeIterator.Current.SelectSingleNode("//my:Response", NamespaceManager).Value;      

                     // Some database calls to insert the data....... 

               
                }  

    So if I have values in my comments and responses controls in two sections such as

    Section 1
    ----------------
    Comment one 
    Response one

    Section 2
    ----------------
    Comment two
    Response two

    When the routine to insert the data completes, I have two rows in the table ( that's good) but with  'Comment one" & "Response one".  That's not good. IN other words, I never get the "Comment two"  or "Response two" values

     

     

     

     

     

  • 12-17-2009 01:12 PM In reply to

    For anyone that's interested.....

    Problem solved. Short answer:  Incorrect XPath notation 

    I was using an absolute path to refernce my controls within my  NodeIterator while loop. Such as....

                     NodeIterator.Current.SelectSingleNode("//my:Comment", NamespaceManager).Value;

    When I should of been using

                     NodeIterator.Current.SelectSingleNode("./my:Comment", NamespaceManager).Value;

    Which now that I understand it, makes sense.  

     

     


     

  • 07-14-2011 02:46 PM In reply to

    You save my day, jeje

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