Click here to Skip to main content
15,891,204 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);

try
{
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.DataBind();
ExcelImportGrid.Caption = Path.GetFileName(strFileName);


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

1 solution

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


more info can be found here[^].
 
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