Javier Rodzs

Javier Rodzs

  • NA
  • 8
  • 3.9k

cannot convert from 'string' to 'System.Collections.Generic.IEnumerabl

Dec 17 2020 12:08 PM
Im trying to export results to a txt file, I need to include all rows and columns. In my query below I can see in the console all the rows and columns, when I use "File.WriteAllText", it only write one row with all columns, when I try to use "File.WriteAllLines" i receive the error msg "cannot convert from 'string' to 'System.Collections.Generic.IEnumerable" . any help really appreciated
  1. using System;  
  2. using Microsoft.AnalysisServices.AdomdClient;  
  3. using System.IO;  
  4. using System.Diagnostics;  
  5. using System.Text;  
  6. using System.Collections.Generic;  
  7. using System.Linq;  
  8. namespace DaxQuery  
  9. {  
  10. class Program  
  11. {  
  12. private const string V = "";  
  13. static void Main(string[] args)  
  14. {  
  15. AdomdConnection adomdConnection = new AdomdConnection("Data Source=localhost:60100");  
  16. String query = @"  
  17. EVALUATE  
  18. SUMMARIZECOLUMNS(  
  19. Customer[City],  
  20. Customer[Country-Region],  
  21. Customer[Customer],  
  22. Customer[Customer ID]  
  23. )  
  24. ";  
  25. AdomdCommand adomdCommand = new AdomdCommand(query,adomdConnection);  
  26. /******************************************************* 
  27. connection 
  28. *******************************************************/  
  29. adomdConnection.Open();  
  30. AdomdDataReader reader = adomdCommand.ExecuteReader();  
  31. // Create a loop for every row in the resultset  
  32. while(reader.Read())  
  33. {  
  34. String rowResults = "";  
  35. // Create a loop for every column in the current row --need to add header  
  36. for (  
  37. int columnNumber = 0;  
  38. columnNumber<reader.FieldCount;  
  39. columnNumber++  
  40. )  
  41. {  
  42. rowResults += $"\t{reader.GetValue(columnNumber)}";  
  43. }  
  44. //Console.WriteLine(rowResults);  
  45. File.WriteAllText(@"C:\Temp\output.txt", rowResults) ;  
  46. //File.WriteAllLines(@"C:\Temp\output.txt", rowResults) ;  
  47. //  
  48. //string rowResults1 = (rowResults);  
  49. //var query1 = rowResults1;  
  50. //File.WriteAllLines(@"C:\Temp\output.txt", query1);  
  51. //  
  52. }  
  53. adomdConnection.Close();  
  54. }  
  55. }  
  56. }  

Answers (1)