1

Sorry for this question as I'm new to asp.net. I need to make Import Csv files into database that is made in sql server and added to web application by entity framework. I managed to export it, but have no clue how to import it other than maybe using StreamReader with regex. Tried using Lumenworks csvreader, but it doesn't cooparate with entity.

1 Answer 1

1

You can look at the CsvHelper NuGet package. You can find parts of the code you need to use here.

Relevant code:

    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
    {
        CsvReader csvReader = new CsvReader(reader);
        csvReader.Configuration.WillThrowOnMissingField = false;
        var countries = csvReader.GetRecords<Country>().ToArray();
        context.Countries.AddOrUpdate(c => c.Code, countries);
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.