I'm not sure what the SQL manager query window is, but I ran it through Access, and it worked. Is SQL manager query window a utility in InfoPath? If so, where do I find it? The SQL syntax was part of the problem, as it turns out...
The SQL syntax, while it works in Access, didn't work in InfoPath. I had to change the * wildcard indicators to %.
From:
select [ID],[Name] from [tDisc] as [tDisc] WHERE tDisc.Name LIKE "*acro*"
To:
select [ID],[Name] from [tDisc] as [tDisc] WHERE tDisc.Name LIKE "%acro%"
I figured this out by reading the KnowledgeBase article above. It said to enter "Sales%" into their example form to enable wildcard searching. I just built the % character into the code, so whatever the user enters will be prepended and appended with %.
The second part of the problem was that I needed to use the ADOAdapter object to enable InfoPath to use more complex SQL actions. Excerpt from the KB article: "...By using the ADOAdapter object, you can modify an SQL statement to perform more complex actions such as using wildcard characters in a query..."
Here's the function I use to perform wildcard queries on the DB, based on the code in the KB article:
function CTRL2_8::OnClick(eventObj)
{
// Get the default SQL command for the form & instantiate variable for new SQL code.
var strOrigSQLCommand = XDocument.QueryAdapter.Command;
var strNewSQLCommand = strOrigSQLCommand;
// Get the query node that you want to modify.
var querySuppliers = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:tDisc");
// Obtain the text that was entered for the wildcard character search, and then clear
// the current query parameter so that InfoPath will leave the current query parameter blank.
var strTitle = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:queryFields/q:tDisc/@Name").text;
querySuppliers.selectSingleNode("@Name").text = "";
if (strTitle != "")
{
strNewSQLCommand += " WHERE [tDisc].[Name] LIKE \"%" + strTitle + "%\"";
}
// This is the query.
XDocument.UI.Alert(strNewSQLCommand);
// Run the query.
XDocument.QueryAdapter.Command = strNewSQLCommand;
XDocument.Query();
// Restore the default table command (for the next time).
XDocument.QueryAdapter.Command = strOrigSQLCommand;
}
I'd like to refactor the code above, specifically the part dealing with XPath, but every attempt I've made breaks the form. I hope someone find this code helpful, and if anyone can succesfully refactor the XPath bit, I'm all ears!
Thanks!