Hey Everyone,
I have a form with a button that I want use to programmatically retrieve sql data, fill it into a sqldatareader object, which I use to populate a stringbuilder string, to finally append as a child to a repeating table element in infopath. The repeating table has five fields in the schema, four of which are text, and one of which is a boolean value. My code seems to work, but unfortunately, when I go to place a check in one of the checkboxes that populates due to this code, the box receives a red highlight telling me "Only 'true' or 'false' allowed".
My code looks like the following:
//reset all rows on the repeating table
XPathNavigator mainDS = MainDataSource.CreateNavigator();
StringBuilder sb = new StringBuilder();
XPathNavigator firstRow = mainDS.SelectSingleNode("/my:myFields/my:updatePartyInfo/my:partyTable/my:group8/my:group9", NamespaceManager);
XPathNavigator lastRow = mainDS.SelectSingleNode("/my:myFields/my:updatePartyInfo/my:partyTable/my:group8/my:group9[position() = last()]", NamespaceManager);
if (firstRow != null && lastRow != null)
firstRow.DeleteRange(lastRow); //Make try/catch to ignore exception if called on a table that has already been cleared (i.e. first run retrieved no records)
using (SqlCommand command = connection.CreateCommand())
{
//command.CommandText = queryString;
command.CommandText = sqlQuery;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
int count = 1;
string my = NamespaceManager.LookupNamespace("my");
string xpath = "/my:myFields/my:updatePartyInfo/my:partyTable/my:group8/my:group9";
XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
while (reader.Read())
{
string partyCode = reader["party_code"].ToString();
string rowId = count.ToString();
string contID = reader["event_code"].ToString();
string address = reader["full_addr"].ToString();
sb.Append("");
sb.Append("" + count.ToString() + "");
sb.Append("" + contID + "");
sb.Append("" + partyCode + "");
sb.Append("" + address + "");
sb.Append("true");
sb.Append("");
count++;
}
}
connection.Close();
sb = sb.Replace("&", "ampersand;"); //fields with ampersands throw schema validation
MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:updatePartyInfo/my:partyTable/my:group8", NamespaceManager).AppendChild(sb.ToString());
I'll also attach as a text file, as I always have trouble getting the formatting to look good on this forum. The selectThisParty field is the checkbox field. In the example above, I'm giving it a value of true. I've tried "TRUE", "false", "FALSE" and leaving the value blank, which all produce errors - the uppercase and blank examples making the field surrounded by the red invalid markers right upon population, whereas the lowercase looks good, until you try and actually populate a check into one of the boxes - then that individual box is surrounded with the red markers.
So my question is - is there something special I have to be doing here when inserting a checkbox versus a text field? I use the sb object compile all of the elements because I noted that large datasets were significantly faster this way - one appendchild() call, rather than multiple appendchildelements(). Does anyone have any ideas what I'm screwing up here? The frustrating thing is if I compare the InnerXML of the table when created by default, the selectThisParty is represented like so:
"false"
. My code produces the same thing, so it seems like it
should work. I'd love to see if anyone has any pointers on what I'm doing wrong, or how I might fix. Thank you in advance for your time.