Click here to Skip to main content
14,838,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to read in a excel.csv file and populate a grid but I'm getting
an exception which specifies "Unspecifed Error" when trying to fill
the data adapter. Any suggestion as to what's wrong?

code snippet....

String strPath = @"\\clw-Grouper\web_data\RFI";

String connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties='Text';", strPath);

string cmdString = string.Format("SELECT * FROM {0}","excel.csv");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(cmdString, connString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet); ExcelImportGrid.DataSource = dataSet;
ExcelImportGrid.Caption = Path.GetFileName(strFileName);

Application["GridTable"] = dataSet;
catch (Exception ex)
MessageLabel.Text = ex.Message;

1 solution

You are using an excel connector not a csv connector.
Better try:
select TerritoryID
from openrowset('MSDASQL'
               ,'Driver={Microsoft Access Text Driver (*.txt, *.csv)}'
               ,'select * from C:\myfileName.CSV')

more info can be found here[^].

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