Code Monkey home page Code Monkey logo

Comments (5)

MarkPflug avatar MarkPflug commented on September 20, 2024 1

Just pushed Sylvan.Data 0.2.0-b0001 to nuget: https://www.nuget.org/packages/Sylvan.Data/0.2.0-b0001
You'll need to catch Sylvan.Data.DataBinderException which now has an Ordinal property. The InnerException will be the FormatException that you previously caught. Let me know if that works for you and it will be included in the final 0.2.0 release.

from sylvan.

vgebrev avatar vgebrev commented on September 20, 2024
        fileStream.Seek(0, SeekOrigin.Begin);
        var csvDataReaderOptions = new CsvDataReaderOptions()
        {
            Schema = new ImportCsvSchema().Schema
        };
        using var streamReader = new StreamReader(fileStream, Encoding.UTF8, leaveOpen: true);
        using var csvReader = CsvDataReader.Create(streamReader, csvDataReaderOptions) ;
        var binder = DataBinder.Create<TParseResult>(csvReader, new DataBinderOptions() { BindingMode = DataBindingMode.AllColumns });
        while (csvReader.Read())
        {
            try
            {
                binder.Bind(csvReader, parseResult);
            }
            catch (FormatException exception)
            {
                // TODO: Figure out which column was being parsed/bound
            }
        }

columns are mostly strings, but a few DateTimes and Decimals as follows:
new Column.Builder( nameof(CsvParseResult.Date), typeof(DateTime), allowNull: true).Build(),
new Column.Builder( nameof(CsvParseResult.Amount), typeof(decimal), allowNull: true).Build(),

Short of manually trying to parse the columns I know could have issues, I haven't found a way to get what I need from the reader, binder, or exception states.

from sylvan.

MarkPflug avatar MarkPflug commented on September 20, 2024

Unfortunately, there isn't currently a way to discover which column has the error. This is something I've been meaning to add though, so this is a good reminder that I need to implement it.

from sylvan.

vgebrev avatar vgebrev commented on September 20, 2024

Holy smokes, that was quick! Thank you kindly, it was exactly what I needed.

from sylvan.

MarkPflug avatar MarkPflug commented on September 20, 2024

If you've found these libraries useful, give it a star, helps other people find it.

from sylvan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.