Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Please have a look at the following code which I am using to import csv file into a sql table:

string Filepath = Server.MapPath("Documents") + "\\" + System.DateTime.Now.ToString("dd_MM_yyyy_mm_ss_") + fupFile.FileName;
                        if (FileExt == ".xls")
                            sExcelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Filepath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;\"";
                        else if (FileExt == ".xlsx")
                            sExcelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Filepath + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;\"";
                            sExcelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Filepath + ";Extended Properties=\"text;HDR=YES;FMT=Delimited\"";

Here,I am able to import .xls and .xlsx. But, when I try to import .csv file, its giving an error. I tried searching in google for the solution, but not getting the suitable solution.

Any help or suggestion would be greatly appreciated.


Share this answer
Try using a "text" connection string such as

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\csvfolder\;Extended Properties="text;HDR=Yes;FMT=Delimited";[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900