473,407 Members | 2,359 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,407 software developers and data experts.

Querying a CSV File

I have a csv file here that is output from another program. Once this
csv has been completed the information needs to be extracted in
multiple formats into a formatted excel spreadsheet (sheet a is
ordered a certain way with specific information and summary rows, ...)

I created the code listed below and tested it multiple times with
success. After which I ported the code to another application and it
ceased working. At first I thought the problem was with the file
being on a network location so I copied the file locally (and
schema.ini).

Dim CMD As OdbcCommand
Dim ConnDir As String = CSVFileName.Substring(0,
CSVFileName.LastIndexOf("\") + 1)
Dim Conn As New OdbcConnection("Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & ConnDir & ";Extensions=asc,csv,tab,txt;")
'IMEX=1;Persist Security Info=False")

Dim DR As OdbcDataReader
Dim SQL As String = "SELECT * FROM " & CSVFileName.Trim & " ORDER BY
PCN"
CMD = New OdbcCommand(SQL, Conn)
Conn.Open()
DR = CMD.ExecuteReader

'ERROR [42S02] [Microsoft][ODBC Text Driver] The Microsoft Jet
database engine could not find the object 'file.csv'. Make sure the
object exists and that you spell its name and the path name correctly.

One of the first responses I expect to see - "Is the file locked?"
A: I'm not sure how to check that but since the same code worked
before I don't see how

Any assistance is appreciated.

Christian

Apr 27 '07 #1
2 2252

I found these notes:

<parameters>
<parameter name="Provider" value="Microsoft.Jet.OLEDB.4.0"
isSensitive="false" />
<!--
Notice the Data Source of a textfile is the DIRECTORY, not the full
path/filename
The Select statement looks like:
"Select * from mytextfile.txt"
-->

<parameter name="Data Source" value="c:\TextFilePubsEquiv\"
isSensitive="false" />
<parameter name="Extended Properties"
value="'text;HDR=YES;FMT=Delimited'" isSensitive="false" />
</parameters>
Which, let me translate.

The DataSource is the DIRECTORY.

The select statement is:
Select * from mytextfile.txt
Here is where you can screw up.

Setting the DataSource to the full path/filename.
Aka, the DataSource is NOT
c:\TextFilePubsEquiv\mytextfile.txt
and the select statement is NOT the full path/filename.
Select * from c:\TextFilePubsEquiv\mytextfile.txt
I think you're doing it right, but in you sample code (if you need to
repost) put something simpler like:
Dim ConnDir As String = "C:\mydirectory\"
dim CSVFileName as string = "mytextfile.txt"

...

Also, be very very anal about every space , semi colon, etc in your
connection string.

<ge*******@otc.eduwrote in message
news:11*********************@r3g2000prh.googlegrou ps.com...
I have a csv file here that is output from another program. Once this
csv has been completed the information needs to be extracted in
multiple formats into a formatted excel spreadsheet (sheet a is
ordered a certain way with specific information and summary rows, ...)

I created the code listed below and tested it multiple times with
success. After which I ported the code to another application and it
ceased working. At first I thought the problem was with the file
being on a network location so I copied the file locally (and
schema.ini).

Dim CMD As OdbcCommand
Dim ConnDir As String = CSVFileName.Substring(0,
CSVFileName.LastIndexOf("\") + 1)
Dim Conn As New OdbcConnection("Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & ConnDir & ";Extensions=asc,csv,tab,txt;")
'IMEX=1;Persist Security Info=False")

Dim DR As OdbcDataReader
Dim SQL As String = "SELECT * FROM " & CSVFileName.Trim & " ORDER BY
PCN"
CMD = New OdbcCommand(SQL, Conn)
Conn.Open()
DR = CMD.ExecuteReader

'ERROR [42S02] [Microsoft][ODBC Text Driver] The Microsoft Jet
database engine could not find the object 'file.csv'. Make sure the
object exists and that you spell its name and the path name correctly.

One of the first responses I expect to see - "Is the file locked?"
A: I'm not sure how to check that but since the same code worked
before I don't see how

Any assistance is appreciated.

Christian

Apr 27 '07 #2
You are correct. I was just about to post that I'd solved the problem
using exactly what you said.

Thanks for the assistance.
On Apr 27, 1:39 pm, "sloan" <s...@ipass.netwrote:
I found these notes:

<parameters>
<parameter name="Provider" value="Microsoft.Jet.OLEDB.4.0"
isSensitive="false" />
<!--
Notice the Data Source of a textfile is the DIRECTORY, not the full
path/filename
The Select statement looks like:
"Select * from mytextfile.txt"
-->

<parameter name="Data Source" value="c:\TextFilePubsEquiv\"
isSensitive="false" />
<parameter name="Extended Properties"
value="'text;HDR=YES;FMT=Delimited'" isSensitive="false" />
</parameters>

Which, let me translate.

The DataSource is the DIRECTORY.

The select statement is:
Select * from mytextfile.txt

Here is where you can screw up.

Setting the DataSource to the full path/filename.
Aka, the DataSource is NOT
c:\TextFilePubsEquiv\mytextfile.txt

and the select statement is NOT the full path/filename.
Select * from c:\TextFilePubsEquiv\mytextfile.txt

I think you're doing it right, but in you sample code (if you need to
repost) put something simpler like:

Dim ConnDir As String = "C:\mydirectory\"
dim CSVFileName as string = "mytextfile.txt"

..

Also, be very very anal about every space , semi colon, etc in your
connection string.

<ge0193...@otc.eduwrote in message

news:11*********************@r3g2000prh.googlegrou ps.com...
I have a csv file here that is output from another program. Once this
csv has been completed the information needs to be extracted in
multiple formats into a formatted excel spreadsheet (sheet a is
ordered a certain way with specific information and summary rows, ...)
I created the code listed below and tested it multiple times with
success. After which I ported the code to another application and it
ceased working. At first I thought the problem was with the file
being on a network location so I copied the file locally (and
schema.ini).
Dim CMD As OdbcCommand
Dim ConnDir As String = CSVFileName.Substring(0,
CSVFileName.LastIndexOf("\") + 1)
Dim Conn As New OdbcConnection("Driver={Microsoft Text Driver (*.txt;
*.csv)};Dbq=" & ConnDir & ";Extensions=asc,csv,tab,txt;")
'IMEX=1;Persist Security Info=False")
Dim DR As OdbcDataReader
Dim SQL As String = "SELECT * FROM " & CSVFileName.Trim & " ORDER BY
PCN"
CMD = New OdbcCommand(SQL, Conn)
Conn.Open()
DR = CMD.ExecuteReader
'ERROR [42S02] [Microsoft][ODBC Text Driver] The Microsoft Jet
database engine could not find the object 'file.csv'. Make sure the
object exists and that you spell its name and the path name correctly.
One of the first responses I expect to see - "Is the file locked?"
A: I'm not sure how to check that but since the same code worked
before I don't see how
Any assistance is appreciated.
Christian- Hide quoted text -

- Show quoted text -

Apr 27 '07 #3

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

Similar topics

6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
2
by: Richard L Rosenheim | last post by:
I loaded a XSLT stylesheet into a XMLDocument to retrieve some of the data. I received an exception when the SelectNodes method was invoked. The message was "System.Xml.XPath.XPathException -...
0
by: Chris | last post by:
Hi all, I have a web site which allows our customers to write data via forms into an access table stored on our ISP's remote server. My question is how do I efficiently retrieve the data? ISP...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
0
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: Job Lot | last post by:
i am querying excel file as follows Dim conn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source='" & "C:\Temp\SSPortfolio.xls" & " '; " & _ "Extended Properties=Excel...
5
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an...
2
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding :...
16
Dököll
by: Dököll | last post by:
Hey Gang! I just ran through a wonderful Microsoft video for VS 2005 Web Dev and SQL 2005 Express. Data added to SQL .mdf file through VS web site... How does one query the data in the SQL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.