473,669 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OleDbDataAdapte r.

Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
Dim conn As New OleDb.OleDbConn ection(ConStr)

Dim da As New OleDb.OleDbData Adapter("Select * from " & pathfile, conn)
da.Fill(DataSet Obj)

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 5063
I figured out what was happening, but not why.

It seems that if I run the program as:

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

It drops the first line. If I run it as

Dim da As New OleDb.OleDbData Adapter("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.comwrot e in message
news:uS******** ******@TK2MSFTN GP03.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 OleDbDataAdapte r.

Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
Dim conn As New OleDb.OleDbConn ection(ConStr)

Dim da As New OleDb.OleDbData Adapter("Select * from " & pathfile, conn)
da.Fill(DataSet Obj)

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.comschr ieb:
It seems that if I run the program as:

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

It drops the first line. If I run it as

Dim da As New OleDb.OleDbData Adapter("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.connections trings.com/?carrier=textfi le>

--
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=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""

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******** ********@TK2MSF TNGP06.phx.gbl. ..
"tshad" <t@home.comschr ieb:
>It seems that if I run the program as:

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

It drops the first line. If I run it as

Dim da As New OleDb.OleDbData Adapter("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.connections trings.com/?carrier=textfi le>

--
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.comschr ieb:
Dim ConStr As String = _
"Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
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
17972
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 example is if i have a login_history table, and i'm logged in, but i want to display the date of my previous login. if the login_history table has user_id and login_date which makes up the primary key, how can i get the most recent login (minus the...
4
1371
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 | TicketNo | evaluation | Username ------------------------------------------------------------------------------- 1 1 9 Jamie 2 1 8.5 ...
6
3785
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 trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
11
1941
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 of ID's). I am looking to be able to call an ID and its Image from the database, but also have returned the previous ID and the next ID, even when those actual ID's are not necessarily +1 and -1 to the ID being called. For example, I want to...
6
4840
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 SalesManName AT Alan Time
6
13754
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 t1 ON relevant_stuff WHERE (lots of conditions) After re-reading the relevant pat ofVol 1 of the SQL Reference I am unablee to see how this is possible.
16
13572
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 document.form1.itemcross.length = 0; The only problem is that it leaves the optgroups. How do I also get rid of the optgroups? Thanks
18
1500
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 way to illustrate the problem I'm having): from SocketServer import * from socket import * from select import select class myHandler(StreamRequestHandler):
3
4751
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 one line and when i read for the next time , my program shuld read only second line discarding first line.. i did it with ignore function but it is taking lot of time to reach
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.