Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
i want to connet with .csv file but the following error is occur ?

System.Data.OleDb.OleDbException: 'E:\cpjain\testswcf\excel\01061102.CSV' is not a valid path.


my code is following
using ( OleDbConnection csvConnection = new OleDbConnection(("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+filename + ";Extended Properties=Text;")))
   {
       using (  OleDbCommand csvCommand = new OleDbCommand("SELECT * FROM 01061102.csv", csvConnection))
       {
           csvConnection.Open();

           // Using a DataReader to process the data
           using (OleDbDataReader reader = csvCommand.ExecuteReader())
           {
               while (reader.Read())
               {
                   // Process the current reader entry...
               }
           }

           // Using a DataTable to process the data
           using (OleDbDataAdapter adp = new OleDbDataAdapter(csvCommand))
           {
               DataTable tbl = new DataTable("MyTable");
               adp.Fill(tbl);

               foreach (DataRow row in tbl.Rows)
               {
                   // Process the current row...
               }
           }
       }
   }


[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 31-May-11 23:15pm
v2

try this way :)
using System.IO;
if(File.Exist(filename))
{

///put your code here

}
else
{
//invalid file path

}
 
Share this answer
 
v2
Check that the file exists, and that you have access permissions. If it is a network path or USB drive (as looks likely) check it is accessible and plugged in correctly.
 
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