Databases Reference
In-Depth Information
//Close the connection.
con.Close();
Methods
After the command is defined, it has to be executed. There are various ways to execute of
a command, depending on what result you expect:
.
ExecuteCellSet executes the command and receives a result in the form of a multi-
dimensional cellset. (We discuss multidimensional cellsets in the “Using the CellSet
Object to Work with Multidimensional Data” section later in this chapter.)
.
ExecuteReader executes the command and receives a result in the form of the
AdomdDatareader class.
.
ExecuteXmlReader returns a result in the form of an XML/A result (either Rowset or
MDDataSet ).
.
ExecuteNonQuery executes the command, but does not return a result.
.
Execute returns an object whose type depends on the request that has been execut-
ed: CellSet , AdomdDataReader , or NULL .
ExecuteCellSet
ExecuteCellSet executes the command and returns the CellSet object, which is intended
for work with multidimensional data. The CellSet object, in the simplest case, is created
by the ExecuteCellSet command and comes back to the user already initialized and
populated with data. This command can be used only for executing MDX queries. If you
use it to execute a SQL or data-mining query, ADOMD.NET will not return a result and
will instead throw an exception (see Listing 33.14).
LISTING 33.14
Executing an MDX Query and Retrieving a Cellset
// Connect to the server.
AdomdConnection con = new AdomdConnection();
con.ConnectionString = “Datasource=localhost; Initial Catalog=Foodmart 2008”;
con.Open();
//Create a simple MDX request.
String cmdText = “SELECT Measures.Members ON COLUMNS FROM [Warehouse and Sales]”;
AdomdCommand command = new AdomdCommand(cmdText,con);
//Execute a method that returns CellSet.
CellSet cellset = command.ExecuteCellSet();
//Close the connection.
con.Close();
 
Search WWH ::




Custom Search