Databases Reference
In-Depth Information
DataSet object from a single source of data, you probably want to use the same connec-
tion multiple times and maintain the life of the connection yourself instead of having
DataAdapter do it for you (see Listing 33.25).
LISTING 33.25
You Can Pass an Existing AdomdCommand Object to a Data Adapter
string commandText = “SELECT Measures.Members ON COLUMNS FROM [Warehouse and Sales]”;
string connectionString = “Datasource=localhost; Initial Catalog=Foodmart 2008;”;
AdomdConnection con = new AdomdConnection(connectionString);
con.Open();
AdomdCommand command = new AdomdCommand(commandText, con);
AdomdDataAdapter dataAdapter = new AdomdDataAdapter(command);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
con.Close();
NOTE
The current version of ADOMD.NET supports the DataAdapter and DataSet objects
only for reading data from the server, not for writing. If you need your application to
change data on the server (to write back and perform what-if analysis), use the MDX
command UPDATE .
AdomdDataReader
In the preceding section, we described the process of loading data into the DataSet object.
However, a client application often needs to read data, display it in the user interface, or
manipulate it in some other way, rather than store it in memory. In this case, you would
not use the DataSet object. You can use AdomdDataReader , which iterates data in a
forward-only fashion. This object iterates the stream of data while receiving it from the
server, and allows the client application to work with parts of the data before it loads the
full resultset. AdomdDataReader implements the standard IDataReader and IDataRecord
interfaces, as shown in Figure 33.17.
System.Data.IDataReader
System.Data.IDataRecord
AdomdClient.AdomdDataReader
FIGURE 33.17 The ADOMDDataReader object implements the IDataReader and
IDataRecord interfaces.
To iterate the result in IDataReader format is simple enough, and the result looks very
similar to what you would get from iterating data using SqlClient or OledbClient . Listing
 
Search WWH ::




Custom Search