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