示例#1
0
        private void ProcessDataRow(ICsvRow row)
        {
            if (row.AsStringArray().Length != _csvDef.Data.Columns.Length)
            {
                OnRowError(row, $"expected {_csvDef.Data.Columns.Length} fields, found {row.AsStringArray().Length}");
                return;
            }
            var dataRow = _dataRows.NewRow();

            try
            {
                foreach (System.Data.DataColumn col in _dataRows.Columns)
                {
                    var value = row[col.ColumnName];
                    if (value != null)
                    {
                        dataRow[col.ColumnName] = value;
                    }
                    else
                    {
                        dataRow[col.ColumnName] = DBNull.Value;
                    }
                }
                _dataRows.Rows.Add(dataRow);
                Console.WriteLine("name: " + row["Name"]);
            }
            catch (ArgumentException e)
            {
                OnRowError(row, e.Message);
            }
            catch (NoNullAllowedException e)
            {
                OnRowError(row, e.Message);
            }
        }
示例#2
0
 private void OnRowError(ICsvRow row, string msg)
 {
     Console.WriteLine($"Error reading row {row.RowNum}:");
     Console.WriteLine(string.Join(_csvDef.Options.Delimiter, row.AsStringArray()));
     Console.WriteLine(msg);
 }