1

I want to import data from a csv file into SQL Server through C#. CSV file has over 2000 columns when converted.

What is the best way to approach this?

It's going to be an ongoing process and I am looking to perform CRUD operations.

I tried converting csv into datatable and used SQLBulkCopy to insert which seems to work for me. I am confused on how to structure the SQL table, since there is a limit of 1024 columns.

5
  • You mentioned SqlBulkCopy worked fine for you, did it work fine with 2000 columns? Commented Mar 30, 2019 at 2:29
  • The problem is when saving it to the SQL table. It throws me an exception of having more than 1024 columns. Commented Mar 30, 2019 at 2:30
  • 4
    You can split your Table into two tables of 1000 columns each, related by common primary key value. In C# side as well split your datatable into two. Commented Mar 30, 2019 at 2:34
  • Similar question may be helpful: stackoverflow.com/questions/54658240/… Commented Mar 30, 2019 at 5:30
  • @AmitKumar I ended up doing that. Thank you Commented Apr 2, 2019 at 23:29

1 Answer 1

1

You can split your Table into two tables of 1000 columns each, related by common primary key value. In C# side as well split your datatable into two.

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.