By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

CSV select not reading the first line

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.