using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks; using tApi.Actions.DTO; namespace tApi.Actions { public class ReportActionscs { public static ReportDTO ReadData(ReportDTO report) { report.readedRows = new List(); try { if (report.connectionString != null) { using (var connection = new SqlConnection(report.connectionString)) { var command = new SqlCommand(report.selectRead, connection); connection.Open(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var row = new List(); ExpandoObject obj = new ExpandoObject(); var store = (IDictionary)obj; for (int i = 0; i < reader.FieldCount; i++) { store.Add(reader.GetName(i), reader[i]); } dynamic lst = obj; report.readedRows.Add(lst); } } connection.Close(); report.success = true; } } } catch(Exception e) { report.success = false; report.message = e.ToString(); } return report; } } }