c# - Getting data from SSAS cube using ADOMD XMLReader -
i have cube , trying retrieve data using following code. don't know number of columns , rows query return. i want read value of each column going on each row.
void outputdatawithxml() { //open connection local server. adomdconnection conn = new adomdconnection("data source=localhost"); conn.open(); //create command retrieve data. adomdcommand cmd = new adomdcommand(@"with member [measures].[freightcostperorder] [measures].[reseller freight cost]/[measures].[reseller order quantity], format_string = 'currency' select [geography].[geography].[country].&[united states].children on rows, [date].[calendar].[calendar year] on columns [adventure works] [measures].[freightcostperorder]", conn); //execute command, retrieving xmlreader. system.xml.xmlreader reader = cmd.executexmlreader(); **// how values form each column here ???? // want read value of each column going on each row** console.writeline(reader.readouterxml()); //close reader, connection reader.close(); conn.close(); //await user input. console.readline(); }
following link says fastest way retrieve data ssas cube xmlreader
http://msdn.microsoft.com/en-us/library/ms123479(v=sql.105).aspx
once have xmlreader, you'll want cellset read out data , metadata.
see https://technet.microsoft.com/en-us/library/ms123476(v=sql.110).aspx in section "retrieving data in disconnected state"
string demonstratedisconnectedcellset() { //create new string builder store results system.text.stringbuilder result = new system.text.stringbuilder(); //connect local server using (adomdconnection conn = new adomdconnection("data source=localhost;")) { conn.open(); //create command, using connection adomdcommand cmd = conn.createcommand(); cmd.commandtext = @" member [measures].[freightcostperorder] [measures].[reseller freight cost]/[measures].[reseller order quantity], format_string = 'currency' select [geography].[geography].[country].&[united states].children on rows, [date].[calendar].[calendar year] on columns [adventure works] [measures].[freightcostperorder]"; //execute query, returning xmlreader system.xml.xmlreader x = cmd.executexmlreader(); //at point, xmlreader stored on disk, //transmitted, modified, cached, or otherwise manipulated //load cellset specified xml cellset cs = cellset.loadxml(x); //now xmlreader has finished being read //we can close , connection, while //cellset can continue being used. x.close(); conn.close(); //output column captions first axis //note procedure assumes single member exists per column. result.append("\t"); tuplecollection tuplesoncolumns = cs.axes[0].set.tuples; foreach (tuple column in tuplesoncolumns) { result.append(column.members[0].caption + "\t"); } result.appendline(); //output row captions second axis , cell data //note procedure assumes two-dimensional cellset tuplecollection tuplesonrows = cs.axes[1].set.tuples; (int row = 0; row < tuplesonrows.count; row++) { result.append(tuplesonrows[row].members[0].caption + "\t"); (int col = 0; col < tuplesoncolumns.count; col++) { result.append(cs.cells[col, row].formattedvalue + "\t"); } result.appendline(); } return result.tostring(); } // using connection }
Comments
Post a Comment