473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CSV connection string

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.

Aug 21 '07 #1
4 7809
gsauns wrote:
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
Aug 21 '07 #2
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

Aug 22 '07 #3
'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
Aug 22 '07 #4
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.

Aug 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: AMC | last post by:
Hi, I'm using an include file to store the connection string to a database. Whenever I try to reference that string to open a connection in the page that includes the file I get the error 'empy...
0
by: Jay Douglas | last post by:
Hello, I'm trying to create a Data Links Property window that behaves just like the dialog box in Visual Studio .Net for MS Sql Server connections. I've found a lot of examples that use...
5
by: Matt | last post by:
Hello, What is the best way to handle the database connection string for a class library project that will be compiled and used as a .dll? This .dll will be accessed via classic ASP and in...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
3
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.