protected override void OnWriteNextRow(object[] values) { var line = new StringBuilder(); for (int i = 0; i < Columns.Count; i++) { if (i > 0) { line.Append(File.Separator); } line.Append(ColumnFormatters[i](values[i], Columns[i].Metadata.Format)); } File.TextWriter.WriteLine(line.ToString()); }
private void ShowRows(IEnumerable <Row> rows, Row schemaRow, string tableName, long rowCount = -1) { grid.DataSource = null; _sqlColumns = null; _sqlColumnFormatters = null; if (schemaRow == null) { return; } var tbl = new DataTable(); _sqlColumns = schemaRow.Columns.Where(x => x.UnderlyingType != ColumnType.Uniquifier && x.UnderlyingType != ColumnType.RID).ToArray(); _sqlColumnFormatters = _sqlColumns.Select(x => ColumnFormatters.GetFormatter(tableName, x)).ToArray(); if (bool.TryParse(ConfigurationManager.AppSettings["AutoResizeColumns"], out var autoResizeColumns)) { _autoResize = autoResizeColumns; } foreach (var col in _sqlColumns) { if (new[] { ColumnType.VarBinary, ColumnType.Binary }.Contains(col.UnderlyingType)) { tbl.Columns.Add(col.Name, typeof(byte[])); } else { switch (col.UnderlyingType) { case ColumnType.Int: tbl.Columns.Add(col.Name, typeof(int)); break; case ColumnType.SmallInt: tbl.Columns.Add(col.Name, typeof(short)); break; case ColumnType.TinyInt: tbl.Columns.Add(col.Name, typeof(byte)); break; case ColumnType.BigInt: tbl.Columns.Add(col.Name, typeof(long)); break; case ColumnType.Date: case ColumnType.DateTime: case ColumnType.DateTime2: case ColumnType.SmallDatetime: tbl.Columns.Add(col.Name, typeof(DateTime)); break; case ColumnType.Time: tbl.Columns.Add(col.Name, typeof(TimeSpan)); break; case ColumnType.DateTimeOffset: tbl.Columns.Add(col.Name, typeof(DateTimeOffset)); break; case ColumnType.UniqueIdentifier: tbl.Columns.Add(col.Name, typeof(Guid)); break; default: tbl.Columns.Add(col.Name); break; } } } foreach (var scannedRow in rows) { var row = tbl.NewRow(); foreach (var col in scannedRow.Columns) { row[col.Name] = scannedRow[col] ?? DBNull.Value; } tbl.Rows.Add(row); } grid.Columns.Clear(); grid.AutoGenerateColumns = false; var listItemProps = ListBindingHelper.GetListItemProperties(tbl); var columnCollection = GetCollectionOfBoundDataGridViewColumns(listItemProps, _sqlColumns, tableName); grid.Columns.AddRange(columnCollection.ToArray()); grid.DataSource = tbl; gridStatusRows.Text = $"{grid.Rows.Count} Rows {(rowCount > -1 && rowCount != grid.Rows.Count ? "of " + rowCount : string.Empty)}"; txtCode.Visible = false; grid.Visible = true; }