Retrieving Data from a Database to a Repeating Table that Updates Values in InfoPath Form - InfoPath Dev
in

InfoPath Dev

Retrieving Data from a Database to a Repeating Table that Updates Values in InfoPath Form

Last post 07-30-2009 08:06 AM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-29-2009 01:46 AM

    • Effat
    • Not Ranked
    • Joined on 07-29-2009
    • Posts 1

    Retrieving Data from a Database to a Repeating Table that Updates Values in InfoPath Form

    HELLo, I am using InfoPath to create a repeating table for updating values in a table called Rating in a DataBase. Now, myproblem is that I need to populate the RatingUIDs from the DataBase to the form and then let the user update the RatingValues column.  I wrote this code with fixed values (AA & BB) and it works, but I need to get the RatingUIDs from the DataBase instead of the fixed values. The following code is written inside a button in the form.

     

    public
    void InternalStartup()

    {      

     
    ((ButtonEvent)EventManager.ControlEvents["CTRL7_6"]).Clicked += new ClickedEventHandler(CTRL7_6_Clicked); }         public void CTRL7_6_Clicked(object sender, ClickedEventArgs e)        {             XPathNavigator mainNode = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:AddRating/tns:projObj/tns:ratingFunc/tns:Rating", this.NamespaceManager);             XPathNavigator rptTable = MainDataSource.CreateNavigator().SelectSingleNode( "/dfs:myFields/dfs:dataFields/tns:AddRating/tns:projObj/tns:ratingFunc" , this.NamespaceManager);             XPathNavigator tableElement = rptTable.CreateNavigator().SelectSingleNode( "tns:Rating" , this.NamespaceManager);                        tableElement.DeleteSelf();            XPathNavigator newElement = mainNode.Clone();

               newElement.SelectSingleNode("tns:Ratinguid", this.NamespaceManager).SetValue(“AA”);

                rptTable.AppendChild(newElement);             //newElement.SetValue("11");             XPathNavigator newElement2 = mainNode.Clone();            newElement2.SelectSingleNode("tns:Ratinguid", this.NamespaceManager).SetValue("BB");                       rptTable.AppendChild(newElement2);         }    }}  I also tried this code but it didn't work:XPathNodeIterator ratinguids = this.DataSources["GetRatingforSelectedProject"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/tns:GetRatingForSelectedProjectResponse/tns:GetRatingForSelectedProjectResult/NewDataSet/vRating", this.NamespaceManager);

    XPathNavigator mainNode = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:AddRating/tns:projObj/tns:ratingFunc/tns:Rating", this.NamespaceManager);

    XPathNavigator rptTable = MainDataSource.CreateNavigator().SelectSingleNode( "/dfs:myFields/dfs:dataFields/tns:AddRating/tns:projObj/tns:ratingFunc" , this.NamespaceManager);XPathNavigator tableElement = rptTable.CreateNavigator().SelectSingleNode( "tns:Rating" , this.NamespaceManager);

     

    // tableElement.DeleteSelf();

    foreach (XPathNavigator ratinguid in ratinguids)

    {

    XPathNavigator newElement = mainNode.Clone();newElement.SelectSingleNode("tns:Ratinguid", this.NamespaceManager).SetValue(ratinguid.SelectSingleNode("@ratinguid", this.NamespaceManager).Value);

    rptTable.AppendChild(newElement);

     

    }

     

    this the error message produced when clicking the button:System.Runtime.InteropServices.COMException
    An item with the following index does not exist in the collection: GetRatingforSelectedProject
       at Microsoft.Office.Interop.InfoPath.SemiTrust.DataObjects.get_Item(Object varIndex)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.DataObjectsCollectionWrapper.get_Item(Object varIndex)
       at Microsoft.Office.InfoPath.Internal.DataSourcesHost.get_Item(String name)
       at Template3.FormCode.CTRL7_6_Clicked(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
     Thank You in advance   

     

  • 07-30-2009 08:06 AM In reply to

    Re: Retrieving Data from a Database to a Repeating Table that Updates Values in InfoPath Form

    Hi -- that error message is telling you that you don't have a data connection named 'GetRatingforSelectedProject' in your data connections in your form. Verify that the data connection name I've highlighted in bold in this line from your code is correct:

    XPathNodeIterator ratinguids = this.DataSources["GetRatingforSelectedProject"].CreateNavigator().Select("/dfs:myFields/dfs:dataFields/tns:GetRatingForSelectedProjectResponse/tns:GetRatingForSelectedProjectResult/NewDataSet/vRating", this.NamespaceManager);

    Hilary Stoupa

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