You must Sign In to post a response.
  • Category: SQL Server

    Import data from "CSV" to SQL Server

    Hi Friends,

    I need to import data from CSV file to SQL table.

    This has to be done by either query/ SP or Wizard.

    I have surfed, but am getting results like the below:
    BULK INSERT dbo.TableForBulkData
    FROM 'C:\BulkDataFile.csv'

    but in my csv am not using ", - comma", imy csv looking like a table and its opening in Excel. Now in this case how can i import my csv to table?

    CSV having the same field as table contains.

    Thanks in advance!

    Best Regards,
    Murugesan P
  • #769450
    Hi, i recommend that you use Spire.XLS to export data from .csv file to data table. Here is the code sample:

    Workbook wb = new Workbook();
    System.Data.DataTable datatable = wb.Worksheets[0].ExportDataTable();

  • #769457
    Hi Chris,

    I am not supposed to add any additional dll files.
    Is there any option to do it through StoredProcedure or any other script?

    Murugesan P

  • #769458

    CSV means comma-separated values. How can it be without comma. CSV you can open it in excel then it will show in tabular format. But underlying data will be comma separated. Try to open the file using notepad then you will see the values in actual format.

    Try the code you already shared and let me know if you are getting any error.

    Asheej T K

  • #769471

    If your file is not comma separated , it must be tab(/t) separated. There are multiple ways to do it:

    1.) You can use SQL server wizard.Right click on database =>Tasks =>Import Data=>Select your Excel/CSV file. Next steps are self explanatory. By performing these steps you can insert your data in SQL table.

    2.) Bulk insert via Coding in c#

    3.) If you know SSIS then create SSIS package and run it.

    Anjali Bansal

    Anjali Bansal

    ~Give your best and lead the world

  • Sign In to post your comments