473,385 Members | 1,531 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.

error while displaying csv file into datatable.

Hi all,

I have csv file which i want to show into datatable.

when i try to use oledb to copy content of csv file into datatable not
all rows are getting copied into datatable. Some last rows are
missing. What i observe it if i open csv file in textpad and save
that in file format 'PC' it starts working.

I am not getting why this is happending?

can any one help me.

thanks in advance.

Jul 12 '07 #1
7 2030
So it sounds like the line endings are inconsistent (cr, lf and all
combinations). If this is a case, then perhaps the csv is at fault -
or maybe the problem is coming from some multi-line text (in a field)
that has odd line endings.

Personally, I'd look at this:
http://www.codeproject.com/cs/database/CsvReader.asp

Far more efficient than OLEDB - not sure if you can attach it directly
to a DataTable, though (but then - I very rarely use DataTable ;-p)

Marc
Jul 12 '07 #2
Hi,

thanks for your reply.

I will elaborate my question more clearly. See i have once csv file
which if i open using oledb in datatable is working. then what i did
is open that file using streamreader and write to some temp file using
streamwriter with default encoding. Here why i did this is i want to
add some text as first row so i am counting commas in first line by
opening csv file using streamreader and then insering those many
commas as first columns with data wherever want. Uptil now this logic
was working properly since last 1 year. suddenly it starts giving eror
for one file.

So i am not understanding is it related to encoding which i set or
something else?

Please help me asap.

thanks in advance.

Jul 12 '07 #3
Archana,

Which part is breaking exactly? Is it breaking when it tries to read the
file or breaking when it tries to write to the file?

From the information provided, I agree with Marc. It sounds like some piece
of the data in the csv file might have a comma in it causing your columns to
be off. It might be a good idea to write something that will count the
commas in each line and output it to you so you can check for the error line.

Otherwise, I have found that it is usually safer to use tab delimited files
rather than comma delimited files. The reasoning for this is that it is
usually more likely to have table data with commas in it than table data with
tabs in it.

If you think your data may contain commas or tabs, it is even safer to use
excel files, but it will require more effort and the use of Visual Studio
Tools for Office.

"archana" wrote:
Hi,

thanks for your reply.

I will elaborate my question more clearly. See i have once csv file
which if i open using oledb in datatable is working. then what i did
is open that file using streamreader and write to some temp file using
streamwriter with default encoding. Here why i did this is i want to
add some text as first row so i am counting commas in first line by
opening csv file using streamreader and then insering those many
commas as first columns with data wherever want. Uptil now this logic
was working properly since last 1 year. suddenly it starts giving eror
for one file.

So i am not understanding is it related to encoding which i set or
something else?

Please help me asap.

thanks in advance.

Jul 12 '07 #4
Hi,

thanks for reply.

See my header don't have comma in it. Sor in first row i am inserting
just garbage string like string containing only 'a' character 300
times. Means no comma at all.

Still i am facing problem.

can u tell me whether its related to encoding or realted to some
nonprintable chatacter, What i observer is file have lots of non-
pritable chatacter. I found one strange thing that is if i remove one
character by opening file in textpad every thing starts working
properly.

I am very much confused now.

Please help me asap.
thanks .

Jul 13 '07 #5
I still think "line endings"; it sounds like textpad is fixing the
line-endings when saving, which it only does it it thinks the data is
dirty (i.e. you have removed on character).

I don't know textpad, but I use "Programmers Notepad 2", which has an
option to view line endings. If textpad has something similar, turn it
on and loook at what you see. At the minimum, they should agree on
every line (i.e. "CRLF", "CR", or "LF" on every line). For best
results, they should match what your parser is expecting. But I don't
use OLEDB from .NET, so I don't know what it wants - the link I posted
will accept any suitable line ending.

Marc
Jul 13 '07 #6
Still, you never answered my question. Is it breaking when your application
tries to read the file or is it breaking when you try to write to the file?
"archana" wrote:
Hi,

thanks for reply.

See my header don't have comma in it. Sor in first row i am inserting
just garbage string like string containing only 'a' character 300
times. Means no comma at all.

Still i am facing problem.

can u tell me whether its related to encoding or realted to some
nonprintable chatacter, What i observer is file have lots of non-
pritable chatacter. I found one strange thing that is if i remove one
character by opening file in textpad every thing starts working
properly.

I am very much confused now.

Please help me asap.
thanks .

Jul 13 '07 #7
On Thu, 12 Jul 2007 03:51:07 -0700, archana
<tr**************@yahoo.comwrote:
>Hi all,

I have csv file which i want to show into datatable.

when i try to use oledb to copy content of csv file into datatable not
all rows are getting copied into datatable. Some last rows are
missing. What i observe it if i open csv file in textpad and save
that in file format 'PC' it starts working.

I am not getting why this is happending?

can any one help me.

thanks in advance.
Check out a library called FileHelpers. Its really good for this sort
of thing

--
http://bytes.thinkersroom.com
Jul 14 '07 #8

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

Similar topics

2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
2
by: a | last post by:
I get the error that "Argument"1": cannot convert from 'string' to 'System.Data.DataRow' at the foreach loop to add rows to the DataTable...any ideas how to fix this? Paul ...
0
by: Fronky | last post by:
Hope someone can help. I am still learning, so no laughing please. I am displaying records from a database using Response.Write(""); instead of the usual datagrid method. I am doing it this way...
3
by: Macca | last post by:
Hi, I am writing a C# application that needs a lot of calibration data. In a previous C++ application, i used a text file which displayed the various calibration data, between 25 and 40...
5
by: Amjad Farran | last post by:
What is the easiest way to display in a table, a delimited text data saved in a text file? I need an idea so that I can research it! Amjad
4
by: Jason Chan | last post by:
How can I get the month and year a calendar control current displaying? My problem is I want to load a list of event to a calendar so that it display difference style if there a event for a day....
3
by: CLEAR-RCIC | last post by:
I have several images i want to display in an ASP.Net application. The images are being passed to me in binary format from another application. Is there a good way to write them directly to an...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
1
by: =?Utf-8?B?SmFjaw==?= | last post by:
Hi, I have a simple code where I am trying to capture a recordset in a grid veiw using a button click event. Data is connected to sql server 2000. However, I am getting error at the line...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.