473,761 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading CSV file using OleDB not reading 1st line

I have a program that is reading a csv file into a dataset. I want it to
read the 1st line as data. But it ignores it.

I have the Connection set up as:

OleDbConnection csvConnection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Te xt;HDR=Yes;FMT= Delimited\"");

or

OleDbConnection csvConnection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Te xt;HDR=No;FMT=D elimited\"");

Either way (with HDR set to Yes or No), it doesn't read the 1st line.

Is there something else I need to do to get it to read that line?

I am reading it as:

da = new OleDbDataAdapte r("Select * from " +
strFile,csvConn ection);
da.Fill(ds);

Thanks,

Tom

Feb 8 '08 #1
2 5028
Can DataTable read from an IDataReader? I recommend:
http://www.codeproject.com/KB/database/CsvReader.aspx

Marc
Feb 8 '08 #2
Figured it out - I ran into this a long time ago.

The problem is that you can't put the path in both the OleDbConnection
(which you have to, I believe) and the Select statement.

So I needed to change the statement from:

da = new OleDbDataAdapte r("Select * from " + strFile,csvConn ection);

to:

da = new OleDbDataAdapte r("Select * from " +
Path.GetFileNam e(strFile),csvC onnection);

I suppose if you put part of the path in the connection string and the rest
of the path in the Select statement it might work, but I am not sure.

Why it ignores the HDR parameter, I don't know. I would think it wouldn't
find the file at all if there were a conflict.

Thanks,

Tom
"tshad" <ts***@dslextre me.comwrote in message
news:eZ******** ******@TK2MSFTN GP03.phx.gbl...
>I have a program that is reading a csv file into a dataset. I want it to
read the 1st line as data. But it ignores it.

I have the Connection set up as:

OleDbConnection csvConnection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Te xt;HDR=Yes;FMT= Delimited\"");

or

OleDbConnection csvConnection = new
OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=" +
csvPath + ";Extended
Properties=\"Te xt;HDR=No;FMT=D elimited\"");

Either way (with HDR set to Yes or No), it doesn't read the 1st line.

Is there something else I need to do to get it to read that line?

I am reading it as:

da = new OleDbDataAdapte r("Select * from " +
strFile,csvConn ection);
da.Fill(ds);

Thanks,

Tom

Feb 8 '08 #3

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

Similar topics

2
10697
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" & "Extended Properties='Text;HDR=NO;FMT=Delimited'"
14
5850
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & ";" & "Extended Properties='Text;HDR=NO;FMT=Delimited'"
3
2759
by: Roland Hall | last post by:
Three times the charm? Sorry for the repost. Trying to get my account right. I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It appears to be in the OLEDB driver also. My connection was:
4
5209
by: Phoebe. | last post by:
Hi, Good Day! Reading 1 excel file into a dataset is fine. How can I read multiple excel with the same data structure into 1 dataset? How can I append those data? Can someone help? Thanks in advanced. rgds,
2
6422
by: Antonio Tirado | last post by:
(ASP.NET c# Question) Hi, I have this odd problem: I receive a CSV File through file upload. Using an OleDB.Datareader i read each row of the file and insert it into SQL. The problem is that for some reason when the file goes over 15k the program gets stuck. All rows are read and inserted correctly into SQL. The program is not generating duplicate entries. It is just there waiting for something
4
12808
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
5
23195
by: Jesse Albert | last post by:
Hiyo, I'm trying to import a CSV file into a datatable using either ODBC or OLEDB. One of the columns contains an IP Address. For some reason, the IP address will not display correctly. All of the other information in the CSV is accurate. For example, 10.80.34.100 displays as 10.8034. All the IPs in the column are displayed like this.
4
5068
by: tshad | last post by:
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...
1
2927
by: paulnamroud | last post by:
Hi Guys, I have a weird problem. While reading my csv file some data a returned as null. When the routine reads values in the column "Size_Code" (like "S",, "M"...) it returns "NULL". When routine reads the other values in the same column "Size_Code" (like 2, 4, 6 ...) it returns the right value. Any clue ? Any help? Shall i have to force a string conversion ? If yes how can i do it the sql statement ?
0
10136
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...
1
9925
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
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
7358
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
6640
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.