How to retrieve data and auto-populate multiple rows of a table - InfoPath Dev
in

InfoPath Dev

How to retrieve data and auto-populate multiple rows of a table

Last post 02-03-2010 02:48 AM by noobslike. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-25-2010 01:07 AM

    How to retrieve data and auto-populate multiple rows of a table

    Hi, really appreciate if someone could help me with this... Basically I have to input a string, and use this string as the identifier to pull out data from an access table. Currently, if the string has only one line in the access table, i can pull the data out and populate a one-row table in infoPath. But the problem is that there can be multiple lines to one identifier. So when that happens, I will need the form to auto increase the number of rows of the table and populate all rows from the access table. For example, let's say I have an id of 12345, in the access database there can be 3 lines have this id but with all other columns different. So when I enter this id into the form, the form will have to increase the originally one-row table into 3 rows and fill in the information. So I am wondering if it is possible to do this without using code? Or if code is necessary, how should I go about it?
  • 01-30-2010 05:20 AM In reply to

    Re: How to retrieve data and auto-populate multiple rows of a table

    Hi -- Is your form based off the Access database? If so, filling in the appropriate query field with your string and running your query should return all your rows. Are you finding this not to be the case in your scenario? How is your form currently set up?

    Hilary Stoupa

  • 02-01-2010 12:34 AM In reply to

    Re: How to retrieve data and auto-populate multiple rows of a table

    Hi Hilary, Yes my form is based on an Access database. Actually I have read one of your blog entries on retrieving data. The code seems to be working except the last part. I modified your code until the following:

                // Get the selected Receiver Number
                string selectedReceiver = MainDataSource.CreateNavigator().SelectSingleNode("/my:Electronic_Receiver/my:Receiver",NamespaceManager).Value;

                //if no form was selected notify the user.
                if (selectedReceiver.Equals(""))
                {
                    MessageBox.Show("Please enter a receiver number.");
                    return;
                }

                string xpath = @"/dfs:myFields/dfs:dataFields/d:testing[@Receiver ='" + selectedReceiver + "']";

                // Get the list of line numbers per the selected receiver.
                XPathNodeIterator lines = this.DataSources["testing"].CreateNavigator().Select(xpath,NamespaceManager);

                //If nothing was found, then return; there will be no items to insert
                if (lines.Count == 0)
                {
                    return;
                }

                //Get the line insertion point
                XPathNavigator lineList = MainDataSource.CreateNavigator().SelectSingleNode("/my:Electronic_Receiver/my:Itemize1", NamespaceManager);

                //Add the rows to the main DOM.
                foreach (XPathNavigator line in lines)
                {
                    try
                    {
                        // Get this line's values from the secondary DOM.
                        string ln = line.SelectSingleNode("@Ln", NamespaceManager).Value;
                        string item = line.SelectSingleNode("@Item_Number", NamespaceManager).Value;
                        string type = line.SelectSingleNode("@Type", NamespaceManager).Value;
                        string PackSlipQty = line.SelectSingleNode("@Pack_Slip_Qty", NamespaceManager).Value;
                        string ReceiptQty = line.SelectSingleNode("@Receipt_Qty", NamespaceManager).Value;
                        string RequestBy = line.SelectSingleNode("@Req_By", NamespaceManager).Value;

                        // Build a string representing a main DOM line nodeset using the values from the secondary DOM.
                        string lineXml = "<my:Itemize1 xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-03T00:09:57'>"
                                        + "<my:Line>" + ln + "</my:Line>"
                                        + "<my:Item>" + item + "</my:Item>"
                                        + "<my:Pack_Slip_Qty>" + PackSlipQty + "</my:Pack_Slip_Qty>"
                                        + "<my:Receipt_Qty>" + ReceiptQty + "</my:Receipt_Qty>"
                                        + "<my:Store_Location>" + "</my:Store_Location>"
                                        + "<my:Pickup_location>" + "</my:Pickup_location>"
                                        + "<my:Req_By>" + RequestBy + "</my:Req_By>"
                                        + "<my:Shortage_date>" + "</my:Shortage_date>"
                                        + "<my:onhand_location>" + "</my:onhand_location>"
                                        + "<my:Part_type>" + type + "</my:Part_type>"
                                        + "<my:firstarticle_check>" + "</my:firstarticle_check>"
                                        + "<my:daily_inspection>" + "</my:daily_inspection>"
                                        + "<my:pass_qty>" + "</my:pass_qty>"
                                        + "<my:reject_qty>" + "</my:reject_qty>"
                                        + "<my:EQ_results>" + "</my:EQ_results>"
                                        + "<my:RON>" + "</my:RON>"
                                        + "<my:inspector>" + "</my:inspector>" + "</my:Itemize1>";

                        // Load new line string into a temporary XML document
                        XmlDocument tempDoc = new XmlDocument();
                        tempDoc.LoadXml(lineXml);

                        //insert the new line into the main DOM
                        XPathNavigator newLn = tempDoc.CreateNavigator().SelectSingleNode("my:Itemize1", NamespaceManager);
                        lineList.AppendChild(newLn);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Could not insert line.\n\nError message:\n" + ex.Message);
                    }
                }
            }
        }

    The front part seems working fine, until the part where I need to insert the new line into the main DOM. But I can't get the node into "newLn". everytime I tried the value of newLn is "null". does the code not work on access database? Or is there any part I need to modify? If you need more information on the form itself please let me know. Thank you very much!

  • 02-01-2010 03:47 PM In reply to

    Re: How to retrieve data and auto-populate multiple rows of a table

    I think your troubles begin about here:

    // Build a string representing a main DOM line nodeset using the values from the secondary DOM.
    string lineXml = "<my:Itemize1 xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-03T00:09:57'>"

    You need the correct namespace definition -- i think that where it says my="http..." etc, that has not been updated for your form?

    Hilary Stoupa

  • 02-03-2010 02:48 AM In reply to

    Re: How to retrieve data and auto-populate multiple rows of a table

    Erm, sorry for being amateur in this matter, but I am not very familiar with the namespace definition. Could you let me know where I can update the namespace? thanks!
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.