473,385 Members | 1,973 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,385 software developers and data experts.

CSV select not reading the first line

I have a program that is reading a .csv file into a dataset and works fine
except that it is dropping the first line. I assume that is because it is
dropping the header. The problem is the first line is not a header.

This was working before and I am not sure what caused it not to work. I am
using OleDbDataAdapter.

Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)

Dim da As New OleDb.OleDbDataAdapter("Select * from " & pathfile, conn)
da.Fill(DataSetObj)

When I look at the DataSet, all the rows are there except the first line.

I also change the HDR parameter to HDR=Yes just to see what would happen and
it still dropped the header.

What is happening here?

Thanks,

Tom
May 18 '07 #1
4 5054
I figured out what was happening, but not why.

It seems that if I run the program as:

Dim da As New OleDb.OleDbDataAdapter("Select * from " &
"c:\importFile\temp.csv", conn)

It drops the first line. If I run it as

Dim da As New OleDb.OleDbDataAdapter("Select * from " & "temp.csv", conn)

It doesn't drop the first line. That is the only difference. What would
cause this to happen?

Thanks,

Tom

"tshad" <t@home.comwrote in message
news:uS**************@TK2MSFTNGP03.phx.gbl...
>I have a program that is reading a .csv file into a dataset and works fine
except that it is dropping the first line. I assume that is because it is
dropping the header. The problem is the first line is not a header.

This was working before and I am not sure what caused it not to work. I
am using OleDbDataAdapter.

Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)

Dim da As New OleDb.OleDbDataAdapter("Select * from " & pathfile, conn)
da.Fill(DataSetObj)

When I look at the DataSet, all the rows are there except the first line.

I also change the HDR parameter to HDR=Yes just to see what would happen
and it still dropped the header.

What is happening here?

Thanks,

Tom

May 18 '07 #2
"tshad" <t@home.comschrieb:
It seems that if I run the program as:

Dim da As New OleDb.OleDbDataAdapter("Select * from " &
"c:\importFile\temp.csv", conn)

It drops the first line. If I run it as

Dim da As New OleDb.OleDbDataAdapter("Select * from " & "temp.csv", conn)

It doesn't drop the first line. That is the only difference. What would
cause this to happen?
Maybe the first line is considered to contain column names? I suggest to
take a look at the connection string used to instantiate the connection
object. It's possible to specify wether to interpret the first row as
column header line there by setting 'HDR' to 'yes' or 'no' there.

Further information:

<URL:http://www.connectionstrings.com/?carrier=textfile>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 18 '07 #3
I was looking at the connection string and realized that I was specifying
the directory in the select statement. This seems to be the problem.

If you notice, I have "c:\ImportFile\temp.csv" instead of "temp.csv" in my
select statement. This is exactly the same since temp.csv is in the
c:\importFile directory. I could understand the problem if I was changing
the folder from the connection string. But here is the Connection string I
am using:

Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""

Here "Path" is equal to "c:\ImportFile\" (which is why my select statment
with no path works correctly). But I am not changing the directory so why
would the program act differently? It obviously has nothing to do with
schemi.ini files or being in a different directory. It is exactly the same.
So why does it take out the header (1st line) in one and not the other????

Thanks,

Tom

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"tshad" <t@home.comschrieb:
>It seems that if I run the program as:

Dim da As New OleDb.OleDbDataAdapter("Select * from " &
"c:\importFile\temp.csv", conn)

It drops the first line. If I run it as

Dim da As New OleDb.OleDbDataAdapter("Select * from " & "temp.csv", conn)

It doesn't drop the first line. That is the only difference. What would
cause this to happen?

Maybe the first line is considered to contain column names? I suggest to
take a look at the connection string used to instantiate the connection
object. It's possible to specify wether to interpret the first row as
column header line there by setting 'HDR' to 'yes' or 'no' there.

Further information:

<URL:http://www.connectionstrings.com/?carrier=textfile>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 18 '07 #4
"tshad" <t@home.comschrieb:
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
First, I do not know the reason for the problem you are experiencing.
However, you may have to remove the backslash prior to the last double quote
in the connection string. Double quotes cannot be escaped by preceeding
them with a backslash in VB.NET. Instead, they are simply duplicated inside
the string literal, which is already the case in your code snippet.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 19 '07 #5

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

Similar topics

4
by: Mark | last post by:
good spam subject ;). anyway, i'm alittle stumped. i'm in need of putting together a query that gets the next highest salary ( select max ( sal ) - 1?, from an emp_sal type table. another...
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
11
by: Neo Geshel | last post by:
I have an Access DB, from which I am going to pull images. Each image has an associated ID, but the ID's are not necessarily sequential (some images may have been deleted, leaving gaps in the list...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
16
by: Brian D | last post by:
I have a multiple select list that is created dynamically based on a previous selection on an asp page. The first thing I do is to clear the curent option list by ...
18
by: Ron Garret | last post by:
Here's my code. It's a teeny weeny little HTTP server. (I'm not really trying to reinvent the wheel here. What I'm really doing is writing a dispatching proxy server, but this is the shortest...
3
by: xyz | last post by:
Hi, I have a text file around 7GB includes 100 million lines... I want to read the data line by line when I approach my module.. ie., when i read for the first time , my program shuld read only...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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?
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
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,...
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...

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.