Link to home
Start Free TrialLog in
Avatar of Techsavy
Techsavy

asked on

InfoPath secondary data sources

Hi

I am writing data from main data source to secondary data source...using following Code. The secondary data source I am using is a Sharepoint List.
However, the seondary data source does not seem to refresh data.

Any ideas why this is happening?

      public void AgreementNumber_Changed(object sender, XmlEventArgs e)
      {
       string myNamespace = NamespaceManager.LookupNamespace("p");


       
          //Get Secondary Datasources

       DataSource ds = DataSources["Well Data"];

       

          //Clear any previous Rows
          XPathNavigator rootNav = MainDataSource.CreateNavigator();
       
          XPathNodeIterator tblRows = rootNav.Select("/p:WellAssessment/p:Wells/p:Well", NamespaceManager);

       
     



         if (tblRows.Count > 0)
         {

           for (int i = tblRows.Count; i > 0; i--)
             {
                 XPathNavigator repTable = MainDataSource.CreateNavigator();
                XPathNavigator repRows = repTable.SelectSingleNode("/p:WellAssessment/p:Wells/p:Well[" + i + "]", NamespaceManager);
                 repRows.DeleteSelf();
             }



         }


         


         


          XPathNavigator domNav = ds.CreateNavigator();
          XPathNavigator agreeNav = rootNav.SelectSingleNode("/p:WellAssessment/p:Facility/p:AgreementNumber", NamespaceManager);

          string agrNum = agreeNav.Value;

          XPathNodeIterator rows = domNav.Select("/dfs:myFields/dfs:dataFields/dfs:Well_Data[@Agreement_Number='" + agrNum + "']", NamespaceManager);

         


          //Write Secondary Data to MainData Source
          while (rows.MoveNext())
          {
              string uniqueid = rows.Current.SelectSingleNode("@Unique_Well_Identifier", NamespaceManager).Value.ToString();
              string status = rows.Current.SelectSingleNode("@Facility_Status", NamespaceManager).Value.ToString();
              string spuddate = rows.Current.SelectSingleNode("@Spud_Date", NamespaceManager).Value.ToString();
              string product = rows.Current.SelectSingleNode("@Product", NamespaceManager).Value.ToString();

              using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/p:WellAssessment/p:Wells", NamespaceManager).AppendChild())
              {
                  writer.WriteStartElement("Well", myNamespace);
                  writer.WriteAttributeString("WellID", uniqueid);
                  writer.WriteAttributeString("Status", status);
                  writer.WriteAttributeString("SpudDate", spuddate);
                  writer.WriteAttributeString("Product", product);
                  writer.WriteEndElement();
                  writer.Close();
              }

          }
             }

ASKER CERTIFIED SOLUTION
Avatar of Clay Fox
Clay Fox
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial