DataReader Dynamic Writing Blanks Instead of Nulls
See original GitHub issuevar 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;
})
.AsDataReader();
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"));
copy.WriteToServer(parser);
}
If I write just using the datatable its correct, but the reader it writes blanks which is incorrect.
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (3 by maintainers)
Top 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 object.property 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Set
NullValue=""
in the configuration.here is the working fiddle https://dotnetfiddle.net/zZt66A
The values are quoted, not empty, updated here: https://dotnetfiddle.net/K9YTnv