Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We actually wrote our own .NET Framework Data Provider based on the ADOMD data provider. We hope to open source it later this year, but below are some excerpts of how I did what you want to accomplish.</p> <p>I used the ExecuteXmlReader of a AdomdCommand object. The xml that is returned will have a portion for the cells.</p> <pre><code>AdomdCommand command = new AdomdCommand(); command.Connection = new AdomdConnection(connectionString); command.Connection.Open(); command.CommandText = query; var doc = XDcoument.Load(command.ExecuteXmlReader()); var cellData = from cell in doc.Root.Elements(_namespace + "CellData").Elements(_namespace + "Cell") select new { Ordinal = (int)cell.Attribute("CellOrdinal"), FormattedValue = cell.Elements(_namespace + "FmtValue").Any() ? cell.Element(_namespace + "FmtValue").Value : cell.Element(_namespace + "Value").Value, Value = cell.Element(_namespace + "Value").Value, Type = (string)cell.Element(_namespace + "Value").Attribute(_xsiNs + "type"), }; </code></pre> <p>Each cell has a data type. For a given column, we need all the cells in that column.</p> <pre><code>var x = cells.Where(c =&gt; ((c.Ordinal + 1) % columnCount) == columnPosition).Select(t =&gt; t.Type).Distinct(); if (x.Count() &gt; 1) { // if a non number comes back, the type is null, so non numbers are null // on counts of greater than 1 and no nulls, we have multiple number types, make them all double to accommodate the differences if ( !x.Contains(null) ) { // mix of numbers not doubles, default to int if (!x.Contains("xsd:double")) { type = typeof(int); } else { type = typeof(double); } } else { type = typeof(string); } } else { // entire column maybe null, default to string, otherwise check if (x.Count() == 1) { type = ConvertXmlTypeToType(x.First()); } } </code></pre> <p>Finally I have function that converts Xml type to .NET type</p> <pre><code>private Type ConvertXmlTypeToType(string type) { Type t = typeof(string); switch (type) { case "xsd:int": t = typeof(int); break; case "xsd:double": t = typeof(double); break; case "xsd:long": t = typeof(long); break; case "xsd:short": t = typeof(short); break; case "xsd:integer": t = typeof(int); break; case "xsd:decimal": t = typeof(decimal); break; case "xsd:float": t = typeof(float); break; default: t = typeof(string); break; } return t; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload