CSV connection string

G

gsauns

Hello,

I am trying to import a CSV file into an Dataset in my ASP.NET app. I
get the full path from an HTML input (file) control, and then take the
filename string from that also.

My problem seems to be in the connection string. The error I get when
I try to open the connection is:

'C:\Temp\CredentialingReport.csv' is not a valid path. Make sure that
the path name is spelled correctly and that you are connected to the
server on which the file resides.

The problem is, that it absolutely is a valid path. I select the file
from a browser screen, and take the path from that input.

Here is my code. The error occurs at 'connExcel.Open()' :

connExcel = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" +
strFilepath + "';Extended
Properties='text;HDR=Yes;FMT=Delimited(,);';");
cmdExcel = new OleDbCommand("SELECT * FROM [" +
strFilename + "]", connExcel);
daExcel = new OleDbDataAdapter(cmdExcel);
connExcel.Open();


I have seen many other people with this problem in my searches around
the 'net, but none have been truly answered... any ideas?

Thanks.
 
J

John B

gsauns said:
Hello,

I am trying to import a CSV file into an Dataset in my ASP.NET app. I
get the full path from an HTML input (file) control, and then take the
filename string from that also.
<...>
If its just a csv file then you can just access the file directly.
string text = File.ReadAllText(...
text.Split(',');

Or you could read it line by line (if line delimited) and split from there.

JB
 
M

Marc Gravell

I can recommend a good (and free) managed CSV reader:
http://www.codeproject.com/cs/database/CsvReader.asp

I don't do an awful lot with DataSets, so I can't remember if you can
load a DataTable directly from IDataReader - however, it would be
trivial to loop over the data-reader grabbing the fields and setting
into a new DataRow each time. I'm confident that this will out-perform
OleDb.

Marc
 
M

Marc Gravell

'C:\Temp\CredentialingReport.csv' is not a valid path.

Valid to who? If you selected if on a broswer screen it is relative to
the client, not the server; is this the same? Another option is to use
an upload input box (and multipart-mime mode on the form), and simply
upload the csv to the server. The CSV reader I cited can be used on
this upload stream IIRC.

Marc
 
G

gsauns

Thanks to all.

I had the best luck with the first suggestion.
I didn't necessarily need it in a DataSet, i just needed to insert
certain data into a table that has a different structure than
the .csv.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top