InfoPath secondary data sources

Techsavy
Techsavy used Ask the Experts™
on
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();
              }

          }
             }

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Director of Business Integration
Commented:
First question would be why use code and not just the default data connections?

Are you trying to submit the data?  Or you want to see chanegs to the data in your form?  Not sure what you mean by refresh.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial