Import CSV file into SQL Server

后端 未结 12 1699
梦谈多话
梦谈多话 2020-11-22 15:41

I am looking for help to import a .csv file into SQL Server using BULK INSERT and I have few basic questions.

Issues:

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 16:37

    I know that there are accepted answer but still, I want to share my scenario that maybe help someone to solve their problem TOOLS

    • ASP.NET
    • EF CODE-FIRST APPROACH
    • SSMS
    • EXCEL

    SCENARIO i was loading the dataset which's in CSV format which was later to be shown on the View i tried to use the bulk load but I's unable to load as BULK LOAD was using

    FIELDTERMINATOR = ','
    

    and Excel cell was also using , however, I also couldn't use Flat file source directly because I was using Code-First Approach and doing that only made model in SSMS DB, not in the model from which I had to use the properties later.

    SOLUTION

    1. I used flat-file source and made DB table from CSV file (Right click DB in SSMS -> Import Flat FIle -> select CSV path and do all the settings as directed)
    2. Made Model Class in Visual Studio (You MUST KEEP all the datatypes and names same as that of CSV file loaded in sql)
    3. use Add-Migration in NuGet package console
    4. Update DB

提交回复
热议问题