Assign Value from a SQL query to an InfoPath Field - InfoPath Dev
in

InfoPath Dev

Assign Value from a SQL query to an InfoPath Field

Last post 04-28-2010 05:15 PM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 04-22-2010 11:25 AM

    Assign Value from a SQL query to an InfoPath Field

    Hello,

    I've got an InfoPath form that connects and runs a Store Procedure on my SQL Database. The Value returned is a string which i'm then wanting to put into a field on my InfoPath datasource.

    My Connection snippet is:

                    using (SqlCommand command = new SqlCommand("SP_InfoPath", connection))
                           {
                                 command.CommandType =
    CommandType.StoredProcedure;
                                 connection.Open();
                                 command.Transaction = connection.BeginTransaction(
    IsolationLevel.ReadCommitted);
                                SqlDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); while (reader.Read())

                           {

                           builder.Append(reader[0].ToString()); command.

                            }

     When I try to then put that into a field in my infopath datasource with this code:

                   string xpath = "/my:myFields/my:field1";
                                       XPathNavigator field = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
                                      field.SetValue(
    builder.ToString);

     It comes up with error: Operation is not valid, because of the current state of the object.

     The connection is fine as in debug mode builder value is what should be coming through. The destination field is set to string.

    Can anyone advise?

    Thanks, Iri

    -------
  • 04-28-2010 05:15 PM In reply to

    Re: Assign Value from a SQL query to an InfoPath Field

    What event is your code in? This error sounds like what we'd see if we ran code to set a field's value in a changing or validating event rather than in the changed event. See this post for a bit more detail.

    Hilary Stoupa

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