Iterate through reapeating sections and send the data of controls to database as rows - InfoPath Dev
in

InfoPath Dev

Iterate through reapeating sections and send the data of controls to database as rows

Last post 04-06-2011 09:19 PM by Jimmy. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-06-2011 12:00 PM

    Iterate through reapeating sections and send the data of controls to database as rows

    Hi All,

    I have a problem in iterating through repeating sections. My scenario is as follows, I have a repeating section with two textboxes. I can iterate through the controls and catch the values of the controls and send it to database on a button click for the first node of repeating section. Here comes the problem, if i repeat the repeating section and entered the values for the first repeating section and also filled values in second repeating section controls. Now on a button click i want to send all the first repeating section data to one row in database and the second repeating section data to a second row in database. I kept my code in the for loop to catch the data of the repeating section. but i am not able to catch the values of the second repeating section. Is there any way to find the exact node of the repeating section so that i can itereate from first node to second node and catch the values of the second node. The iteration in repeating section has been a night mare for me since many days. Could anyone please help me with this issue.

     Below is the code which i am working on.

    public partial class FormCode

    {

    private string _connstring = @"Server= servername; Initial Catalog = Test ; Integrated Security=SSPI";

    // Member variables are not supported in browser-enabled forms.

    // Instead, write and read these values from the FormState

    // dictionary using code such as the following:

    //

    // private object _memberVariable

    // {

    // get

    // {

    // return FormState["_memberVariable"];

    // }

    // set

    // {

    // FormState["_memberVariable"] = value;

    // }

    // }

    // NOTE: The following procedure is required by Microsoft Office InfoPath.

    // It can be modified using Microsoft Office InfoPath.

    public void InternalStartup()

    {

    ((
    ButtonEvent)EventManager.ControlEvents["CTRL4_5"]).Clicked += new ClickedEventHandler(CTRL4_5_Clicked);

    // EventManager.XmlEvents["/my:myFields/my:group1/my:group2"].Changed += new XmlChangedEventHandler(group2_Changed);

    }

     

     

    public void CTRL4_5_Clicked(object sender, ClickedEventArgs e)

    {

    XPathNavigator navigator = this.MainDataSource.CreateNavigator();

    XmlNamespaceManager objNamespace = this.NamespaceManager;

    XPathNodeIterator iter = navigator.Select("/my:myFields/my:group1/my:group2", NamespaceManager);

     

    while(iter.MoveNext())

    {

    string DD = iter.Current.SelectSingleNode("/my:myFields/my:group1/my:group2/my:DD", NamespaceManager).Value;

    string Name = iter.Current.SelectSingleNode("/my:myFields/my:group1/my:group2/my:Name", NamespaceManager).Value;

     

    SqlConnection _oConnection;

    SqlCommand _oCommand = new SqlCommand();

    _oConnection = new SqlConnection(_connstring);

    _oCommand.Connection = _oConnection;

    _oCommand.CommandType =
    CommandType.Text;

    _oCommand.CommandText = "INSERT INTO test (Choice, Name) values('" + DD + "', '" + Name + "' )";

     

    try

    {

    _oConnection.Open();

    _oCommand.ExecuteNonQuery();

    }

    catch (Exception ex)

    {

    _oConnection.Close();

    }

     

     

    finally

    {

    _oConnection.Close();

    }

    }

    }

    }

     

    Thanks in advance 

     

     

     

  • 04-06-2011 09:19 PM In reply to

    Re: Iterate through reapeating sections and send the data of controls to database as rows

    Here's a hint: relative XPath, not absolute XPath.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.