예제 #1
0
        public static DataTable ToAppInsightsDataTable(this AppInsightsDataTableResponseObject appInsightsDataTableResponse)
        {
            if (appInsightsDataTableResponse == null)
            {
                throw new ArgumentNullException("appInsightsDataTableResponse");
            }

            var dataTable = new DataTable(appInsightsDataTableResponse.Name);

            dataTable.Columns.AddRange(appInsightsDataTableResponse.Columns.Select(column => new DataColumn(column.Name, GetColumnType(column.Type))).ToArray());

            foreach (var row in appInsightsDataTableResponse.Rows)
            {
                var rowWithCorrectTypes = new List <object>();
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    object rowValueWithCorrectType = null;

                    if (row[i] != null)
                    {
                        rowValueWithCorrectType = Convert.ChangeType(row[i], dataTable.Columns[i].DataType);
                    }

                    rowWithCorrectTypes.Add(rowValueWithCorrectType);
                }

                dataTable.Rows.Add(rowWithCorrectTypes.ToArray());
            }

            return(dataTable);
        }
        public static DataTable ToAppInsightsDataTable(this AppInsightsDataTableResponseObject appInsightsDataTableResponse)
        {
            if (appInsightsDataTableResponse == null)
            {
                throw new ArgumentNullException("appInsightsDataTableResponse");
            }

            var dataTable = new DataTable(appInsightsDataTableResponse.Name);

            dataTable.Columns.AddRange(appInsightsDataTableResponse.Columns.Select(column => new DataColumn(column.Name, GetColumnType(column.Type))).ToArray());

            for (int i = 0; i < appInsightsDataTableResponse.Rows.GetLength(0); i++)
            {
                var row = dataTable.NewRow();
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    row[j] = appInsightsDataTableResponse.Rows[i, j] ?? DBNull.Value;
                }

                dataTable.Rows.Add(row);
            }

            return(dataTable);
        }