Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataReader Dynamic Writing Blanks Instead of Nulls

See original GitHub issue
var csvRecordConfiguration = new ChoCSVRecordConfiguration
                                         Delimiter                  = "|",
                                         AutoDiscoverColumns        = true,
                                         AutoDiscoverFieldTypes     = true,
                                         ThrowAndStopOnMissingField = false,
                                         QuoteAllFields             = true, IsDynamicObject = true,
                                         FileHeaderConfiguration = new ChoCSVFileHeaderConfiguration
                                                                       IgnoreColumnsWithEmptyHeader = true,
                                                                       HasHeaderRecord              = true,
                                                                       QuoteAllHeaders              = true

        var parser = new ChoCSVReader(file, csvRecordConfiguration).Select(row =>
                                                                               row.FileLogId   = 183874;
                                                                               row.ProcessCode = "T";
                                                                               return row;

using (var copy = new SqlBulkCopy(connectionString))
            copy.DestinationTableName = tableName;
            copy.EnableStreaming      = true;

            foreach (var mapping in columnMappings) copy.ColumnMappings.Add(mapping);

            copy.ColumnMappings.Add(new SqlBulkCopyColumnMapping("FileLogId", "FileLogId"));
            copy.ColumnMappings.Add(new SqlBulkCopyColumnMapping("ProcessCode", "ProcessCode"));


If I write just using the datatable its correct, but the reader it writes blanks which is incorrect. image

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

Cinchoocommented, Nov 17, 2022

Set NullValue="" in the configuration.

here is the working fiddle

bakes82commented, Nov 16, 2022

The values are quoted, not empty, updated here:

Read more comments on GitHub >

github_iconTop Results From Across the Web

SqlDataReader returns blank instead of null for an int field
When reading a NULL int field from the database, reader["Column1Name"] is blank so the code throws an InvalidCastException at runtime. but this ...
Read more >
Replace nulls with empty strings from DataReader
Either in the SQL query (both SELECTs and INSERT/UPDATES), or in your VB code (if column is null, substitute String.Empty; or if string...
Read more >
SQL SERVER dynamic Query with Like Statement for null ...
I'm trying to execute a SQL dynamic query with nullable parameters using LIKE . If the parameter has a value, the query is...
Read more >
Creating a Dynamic DataReader for easier Property Access
It uses cleaner syntax; All the type casting is gone; The DBNull to .NET NULL assignment is automatic. Good News, Bad News....
Read more >
Using a dynamic DataReader with ADO.NET
Returns a value from the current DataReader record. /// If the field doesn't exist null is returned. /// DbNull values are turned into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found