Ok here is one to get you started, bear in mind I use Infopath Filler 2007 so can't guarantee what doesn't work with web version... I've paraphrased my variable names a bit but should be fairly compilable :).
//To take value from dropdown list then query DB by it as a parameter...
public void SomeButton_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator xpn = (XPathNavigator)e.Source;
xpn.MoveToChild("MyDropDownListElement", xpn.NamespaceURI);
string param = xpn.Value;
if (string.IsNullOrEmpty(param)) {
MessageBox.Show("Please select a valid entry from the dropdown and try again.", "Error");
return;
}
if (!IsFormEmpty) {
if (MessageBox.Show("You are about to load load data " + param+ ". Any unsaved changes to the current data are about to be lost. Do you wish to proceed?",
"Confirm Load", MessageBoxButtons.YesNo) == DialogResult.No)
return;
LoadSomeTestData(param);
IsFormEmpty = false;
return;
}
}
private void LoadSomeTestData(string param)
{
string query = "SELECT [ColName1],[ColName2] FROM [DB_NAME].[dbo].[TableName] WHERE ColName1 = '" + param + "'"; ;
AdoQueryConnection myAdoQueryConnection =
(AdoQueryConnection)(this.DataConnections["MY_DB_CONNECTION"]);
string oldCmd = myAdoQueryConnection.Command;
myAdoQueryConnection.Command = query;
myAdoQueryConnection.Execute();
myAdoQueryConnection.Command = oldCmd;
XPathNavigator queryNav = this.DataSources["MY_DB_CONNECTION"].CreateNavigator();
queryNav = queryNav.SelectSingleNode("//dfs:myFields/dfs:dataFields/d:TableName", this.NamespaceManager);
//And so on, now iterate the main fields and the data fields and swap out the data using XPath cmds.
}