Comments (8)
Can you provide any test data? I create random data with 2000 columns and 2000 rows and there is no exception.
from csvreader.
@jakubmaguza - I sure can, let me put together a sample. Thanks for the help!
from csvreader.
@kirikintha Hi. Unfortunatelly the url is broken. Can you send it one more time?
from csvreader.
@jakubmaguza - here is another attachment. Let's see how this goes. The columns have fairly long names in some places, and some eccentricity, but they are all quoted.
from csvreader.
@kirikintha File works gr8, but I can see only one column in this file with 196 rows.
from csvreader.
I took a quick look at this file and it's braking at last row, where you don't have comma as last character.
from csvreader.
@kirikintha Looking at the sample test @jakubmaguza provided the issue is the parsing mode for the file.
By default the action on a missing field error is ParseError which means if you have a malformed line, the parser will throw an exception.
However you could set this to ReplaceByNull or ReplaceByEmpty, you may still have a issue with SQLBulkCopy as it is very particular about column types but this may be helped with the column default value setting.
I've added further tests around the MissingFieldAction into the code...
[Test]
public void MissingFieldNull()
{
using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
{
csv.SkipEmptyLines = true;
csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;
RowCheck(csv, "a", "b", string.Empty);
RowCheck(csv, "c", "d", null);
Assert.That(csv.ReadNextRecord, Is.False);
}
}
[Test]
public void MissingFieldEmpty()
{
using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
{
csv.SkipEmptyLines = true;
csv.MissingFieldAction = MissingFieldAction.ReplaceByEmpty;
RowCheck(csv, "a", "b", string.Empty);
RowCheck(csv, "c", "d", string.Empty);
Assert.That(csv.ReadNextRecord, Is.False);
}
}
[Test]
public void MissingFieldException()
{
using (var csv = new CsvReader(new StringReader("a,b,\nc,d"), false))
{
csv.SkipEmptyLines = true;
csv.MissingFieldAction = MissingFieldAction.ParseError;
RowCheck(csv, "a", "b", string.Empty);
RowCheck(csv, "c", "d");
Assert.Throws<MissingFieldCsvException>(() => { var x = csv[2]; });
}
}
from csvreader.
Hi everyone, thank you kindly for the update on how to handle the parse errors - I am working with the missing field exception examples and getting farther down the road. I also did an analysis on the file and it is malformed so I am having to go in and try some variation on the DDL and see if I can make it work.
Thank you so much for your help and analysis!
from csvreader.
Related Issues (20)
- Privacy issues in exception handling HOT 1
- Customizable CultureInfo HOT 3
- CsvReader.ReadNextRecord throws IndexOutOfRangeException HOT 2
- Null versus Empty String fields HOT 2
- Can I easily trim tabs?
- Static Fields? HOT 4
- CurrentRecordIndex Does not Update if SkipEmptyLines is True and a row is empty
- Error: 'FileId' field header not found. Parameter name: name
- Error when reading file with Quoted field at end of first row and SkipEmptyLines=false
- Build error MSB4057: The target "Restore" does not exist in the project. HOT 2
- Annotated CSV support ?
- Remove new line characters when giving trimmingOptions
- CsvReader.HandleParseError should not throw an exception when the DefaultParseErrorAction is RaiseEvent HOT 2
- Allow special characters in column headers
- Custom LineBreak Characters as well as `r`n HOT 1
- Custom line break support HOT 1
- Install-Package : A parameter cannot be found that matches parameter name 'Version'. HOT 1
- .
- Headers in different than top row
- Product support question
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csvreader.