Databases Reference
In-Depth Information
// When the user clicks the Execute button, the MDX query to request
//the best-selling product is sent, using the product family that the
//user chose, and the expected number of products, also chosen by
//the user.
private void Execute_Click(object sender, EventArgs e)
{
//Create the command object.
AdomdCommand command = this.con.CreateCommand();
// Make sure that the MDX request contains special labels for
//the parameters.
command.CommandText = “SELECT topcount
(Descendants(StrToMember(@productFamilyMember), [Product].[Products].[Product] )
, @topCount, [Measures].[Unit Sales] ) ON COLUMNS FROM [Warehouse and Sales]”;
// The product family chosen by the user.
//Find the unique name of the tuple that represent the product family
//the user chose in the first request.
string chosenProductFamily = this.productFamiliesTuples
[productFamiliesBox1.SelectedIndex].Members[0].UniqueName;
//Create parameters.
command.Parameters.Add(“productFamilyMember”, chosenProductFamily);
command.Parameters.Add(“topCount”, topCountBox.Value);
//Send the request.
CellSet topProductsCellSet = command.ExecuteCellSet();
topProductsBox1.Items.Clear();
//Fill out the list box with the products returned by this MDX request.
foreach(Tuple tuple in topProductsCellSet.Axes[0].Set.Tuples)
{
topProductsBox1.Items.Add(tuple.Members[0].Caption);
}
}
}
}
This code produces the user interface shown in Figure 33.20.
Asynchronous Execution and Cancellation of
Commands
When you create software that provides a user interface, it is important to make sure that
the user can continue to work with the application while a long-running operation is
being executed. You also need to provide the user with an opportunity to cancel the long-
running operation.
Search WWH ::




Custom Search