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!