I'm trying to query the secondary data source and display the results of the query in a repeat table in the main data source. Obviously something is to working right for me at this point.
I have been using your code I find online, but the major problem I'm having at the moment it I can's seem to be able to refresh the repeat table to show the query results. after
foreach (string colName in columnNames)
{
writer.WriteStartElement(colName, myNamespace);
MessageBox.Show(colName.ToString());
writer.WriteValue(resultRow.GetAttribute(colName, blankNamespace));
writer.WriteEndElement();
}
writer.WriteEndElement();
do I need to have another line of code to display the results copied from secondary data source to the repeat table in the main data source.
Your help will be greatly appreciated.
Thanks
The whole code I have for this is
public void CTRL10_7_Clicked(object sender, ClickedEventArgs e)
{
// retrieve field1's value and store it in a string
string field1 = MainDataSource.CreateNavigator().SelectSingleNode("//dfs:myFields/dfs:queryFields/q:FRAQSTemplate/@CatID", NamespaceManager).Value;
const string queryString = "select * from [FRAQSTemplate] where [CatID] = 3";
// make sure that the search string isn't blank
if (!string.IsNullOrEmpty(field1))
{
// instantiate an object to access the data connection. TestTable1 is the name of the data connection
AdoQueryConnection dc = (AdoQueryConnection)DataConnections["SecondaryConnection"];
// insert field1's value into the query and assign it to the data connection's query
dc.Command = string.Format(queryString);
// run the query
dc.Execute();
//AdoQueryConnection newQuery = (AdoQueryConnection)MainDataSource.QueryConnection;
//newQuery.Execute();
}
else
{
// show an error when field1 is blank
MessageBox.Show("The search field cannot be blank!");
}
}
public void CTRL19_7_Clicked(object sender, ClickedEventArgs e)
{
// store all of the column names in an array, to be used below
string[] columnNames = { "ID", "CatID", "QuestionNO", "Question", "Active", "Version", "TS" };
// store the namespace URLs as strings for easy reference
string myNamespace = NamespaceManager.LookupNamespace("my");
// d is the prefix of the repeating nodes in the secondary data source results, as seen in the data source taskpane
string dNamespace = NamespaceManager.LookupNamespace("d");
// the attributes on the secondary data source results have no prefix, as seen in the data source taskpane
string blankNamespace = NamespaceManager.LookupNamespace("");
// select the node where the results will be placed
XPathNavigator dataFields = MainDataSource.CreateNavigator().SelectSingleNode("//dfs:myFields/my:QueryResults", NamespaceManager);
// select the secondary data source node where the results are located
XPathNavigator queryDataFields = DataSources["SecondaryConnection"].CreateNavigator();
queryDataFields = queryDataFields.SelectSingleNode("//dfs:myFields/dfs:dataFields", NamespaceManager);
// remove all ResultRow children of the my:QueryResults node in the main data source
while (dataFields.MoveToChild("ResultRow", myNamespace))
{
dataFields.DeleteSelf();
}
// iterate through each results node in the secondary data source
foreach (XPathNavigator resultRow in queryDataFields.SelectChildren("FRAQSTemplate", dNamespace))
{
// append a new child to the my:QueryResults node
using (XmlWriter writer = dataFields.AppendChild())
{
// write the element name
writer.WriteStartElement("ResultRow", myNamespace);
// copy over each of the attributes
foreach (string colName in columnNames)
{
writer.WriteStartElement(colName, myNamespace);
MessageBox.Show(colName.ToString());
writer.WriteValue(resultRow.GetAttribute(colName, blankNamespace));
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}
}