Hello,
I have an InfoPath 2007 form that I am trying to write C# code to do the
following: based on one of the three options a user selects, and then
clicking a button, a repeating table would be filled with several rows.
This repeating table is part of the main connection to the database, it
is not a secondary data connection (I don't know if that matters or
not). To try and get this to work, I've tried code from various sites.
They include:
-
Deals with Schema validation errors:
http://www.bensonthomaslive.net/1/post/2009/8/infopath-error-schema-validation-found-non-data-type-errors.html
-
Can insert a blank row, but no data. If I insert data will only place it
on the first row -
http://www.infopathdev.com/blogs/jimmy/archive/2009/03/06/automatically-adding-rows-to-repeating-sections.aspx
-
http://blogs.msdn.com/b/infopath/archive/2006/11/28/the-xsi-nil-attribute.aspx
-
Lots of great examples, but still getting Schema errors -
http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
I am familiar with C# but not so good with anything XML (as it pretty obvious at this point).
The data structure is as follows:
myFields
dataFields
Project
ProjectID
ProjectTitle
ProjectDescription
ProjectTasks
ProjectTaskID
ProjectTaskDescription
ProejctID
ProjectTasks is the repeating table where I want to add multiple rows.
Here's the latest code I have that isn't working:
public void CTRL12_7_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator myRoot;
XPathNavigator node;
myRoot = MainDataSource.CreateNavigator();
node = myRoot.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:Project", NamespaceManager);
DeleteNil(node);
string myNamespace = NamespaceManager.LookupNamespace("dfs");
using (XmlWriter writer = node.AppendChild())
{
writer.WriteStartElement("ProjectTasks", myNamespace);
writer.WriteElementString("ProjectTaskID", myNamespace, "2");
writer.WriteElementString("ProjectTaskDescription", myNamespace, "New Description Here");
writer.WriteElementString("ProjectID", myNamespace, "3");
writer.WriteElementString("TaskAssignedTo", myNamespace, "16");
writer.WriteEndElement();
writer.Close();
}
}
public void DeleteNil(XPathNavigator node)
{
if (node.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance"))
node.DeleteSelf();
}
Any help on this frustrating problem would be greatly appreciated!
Thank you.
-Gumbatman