Reviews US Money Reserve research paper Motivational Quotes  ServicesListed.com Free cell phones   Custom Writing
Try the best slots i found online, you will love it!
Nishanth's Blog | Truncation of fields when CSV file is read using ADO.NET

Truncation of fields when CSV file is read using ADO.NET

by Nishanth 2. November 2008 06:57

I encountered a major problem with ADO.NET CSV reader in one of the projects where CSV File Import played a major role.
When a field in the CSV file with a “–“(hyphen) is read, the characters before the “–“are discarded. For example the model F-150 is read as –150 and T-Bird in the model field is not being read. And some of the values were missing in some of the fields.
Given below is the code I used :

 string strConnString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + folderName + “;Extended Properties=\”text;HDR=Yes; FMT=Delimited; IMEX=1\””;
string sqlSelect = “select * from [" + fileName + "]“;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConnString.Trim());
conn.Open();
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(sqlSelect, conn);
DataSet ds = new DataSet();

ds.ReadXmlSchema(Server.MapPath(”xmlschema.xsd”));

ds.EnforceConstraints = false; 
F-100 reads as -100
K-100 reads as -100
S-100 reads as -100
100-F reads as -100
100-K reads as -100
100-S reads as -100
100$F reads as 100
100$K reads as 100
100$S reads as 100
F100 reads as 100
K100 reads as 100
S100 reads as 100
F\100 reads as 100
K\100 reads as 100
S\100 reads as 100
F.100 reads as .1
K.100 reads as .1
S.100 reads as .1
K-.\\$$$.\\1 reads as -0.1
K\\-22..$$\\21 reads as -22.221
-$\.FSK1 reads as -0.1
This happens only wen there is only one row in thecsv file or more than half the values in a column is having the avove specifiedvalues

 

string strConnString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” + folderName + “;Extended Properties=\”text;HDR=Yes; FMT=Delimited\””;
string sqlSelect = “select * from [" + fileName + "]“;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(
strConnString.Trim());
conn.Open();
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(sqlSelect, conn);
DataSet ds = new DataSet();
adapter.Fill(ds, “Inventory”);
return ds.Tables[0];

Samir found a solution, to add a schema file which identifies all fields in the csv file as string values.
And call DataSet.ReadXMLSchema() method to attach the schema to the DataSet. Also the schema constraints are not enforced .

modified code looks like this..

 

 

adapter.Fill(ds, “Inventory”);
return ds.Tables[0];

Even after using this code values like “F-150″ was read as -150 if there is only one row in the csv file.

May be because ADO.NET does some internal calculation to treat F as floating point or something.. The fun part is that f-150 is read correctly.. problem is with capital letters  . 
So we ended up using a custom third party csv reader . 
Moral of the story… never use ADO.NET csv reader… Always go for a custom CSV parser or a third party library.

Tags: , , , ,

.NET | C#

Comments

5/4/2010 4:31:32 AM #

WoW i love ur blog dude. Nice story and really fun for me to read
Regards budi

Finance United States

5/9/2010 8:33:50 AM #

Thanks for post. It’s really informative stuff.
I really like to read.Hope to learn a lot and have a nice experience here! my best regards guys!

fuel pump United States

6/8/2010 3:16:21 PM #

Great post, thanks for the info, i really needed it.

CFD South Africa

6/8/2010 3:18:03 PM #

I have been searching everywhere for this info.

Thanks

Forex Trading Switzerland

6/28/2010 1:09:01 AM #

COol site man

lesbian singles United States

7/15/2010 10:31:46 AM #

Superb Blog, thanks for helping me with this useful Article. I think it is really a great topic to write about on my Site. Also here is some good information if needed: <A href="...bisheddesktopcomputers.com">refurbished desktop computers</A>

refurbished desktop computers Germany

7/15/2010 3:30:25 PM #

I love you not because of who you are, but because of who I am when I am with you.

New Balance Shoe United Kingdom

8/10/2010 8:58:06 PM #

Hey just testing nice blog

games United States

8/11/2010 12:47:36 AM #

Cool thanks for posting this

games United States

8/11/2010 2:34:43 AM #

Hey just testing nice blog

free games United States

8/16/2010 6:51:55 AM #

Thanks for your post! It's very interesting!

Free DSiWare United States

8/24/2010 5:51:41 PM #

yeah, all of these dating sites just get bombarded with spam, kinda like all these comments.

Free Dating United States

9/2/2010 7:15:21 PM #

wow, I am glad to see the coding to truncating fields when CSV file is being read with ADO.net. I just copied your code for future use Laughing

Forex bullet proof review United States

9/11/2010 6:45:39 AM #

Pingback from web20go.info

RED’s Top Ten Driving Tunes!

web20go.info

12/9/2010 8:42:08 PM #

"No one likes a xp slow, when you startup your computer you want it to be ready to use immediately.SlowXPFix is a risk-free tool that would help you to speed up your slow Windows XP, and get your XP system back to its optimal performance.
"

xp slow People's Republic of China

12/11/2010 3:04:57 PM #

this blog is so very interesting., i love reading it., thanks for the information here....

khan vs maidana fight replay United States

12/16/2010 3:34:06 AM #

This is great information. Folks, listen to this guy. He's very bright and knows what he's talking about. You can't go wrong with following people who can walk the walk - like him. Great information, dude. Just the way I like it!

Betsafe United States

12/17/2010 3:51:35 AM #

It is my honor to read your aticle!Succent language,concise blog,while the content is full of connotation.I like your writing styles very much.Thank you for sharing.

Norgesautomaten United States

12/18/2010 8:38:51 PM #

Amazing ideas! I've bookmarked your site and will be back for more. Keep it up. You've got some great information, unlike many other regurgitated and rehashed blogs.

Norgesautomaten United States

12/19/2010 2:15:18 AM #

Very usefull Info Very Kind of You for sharing

Spilleautomater United States

12/20/2010 5:07:52 AM #

Brilliant blog post.I have bookmarked it already

Casino bonus United States

12/27/2010 7:24:22 PM #

nice article, I merely passed this to a friend that was doing a little amount of research on this subject

cool site Slovakia

12/27/2010 7:31:36 PM #

LG Optimus 7  Combining Style And Substance In One Stunning Handset | Cheaphomeideas.com

cool site Trinidad and Tobago

12/27/2010 7:34:35 PM #

Have you considered about including some social bookmarking buttons to these blogs. At least��for twitter.

cool site El Salvador

12/27/2010 7:48:20 PM #

I do not think the same way, but part you make make a good point

cool site Kyrgyzstan

12/27/2010 7:49:23 PM #

I've stopped by here a couple times and it looks like your blog posts get more informative each time. Keep it up I enjoy reading them.

cool site Germany

12/27/2010 7:51:19 PM #

I was looking for as post about this and found myself here.Nice work and good post.

cool site Ukraine

1/2/2011 3:57:02 PM #

"No one likes a xp slow, when you startup your computer you want it to be ready to use immediately.SlowXPFix is a risk-free tool that would help you to speed up your slow Windows XP, and get your XP system back to its optimal performance.
"

xp slow People's Republic of China

1/12/2011 5:39:54 PM #

nice good website yea nice job our blog will soon be adding reviews on blogs and add them to our blogs as the top best 100 blogs to visit we also do reviews on Consumer Reports reviews��all types of reviews we will get back to you

cool site Italy

1/12/2011 5:40:56 PM #

I am a gay Christian.  The struggle for me was denying what God created ME just as I am.  My journey is to discover that which God created in me, as me, and through me.  When I allowed what God created just to "BE," I found true completeness.  When I began acknowledging God's perfection in my soul, my life shifted for the better.  The sadness many zealot Christians assume gays and lesbians have is just not the case.  I have found 99% more straight men and women who are miserable with their lives.  I find 99% more straight people caught in the void of not knowing themselves or how to celebrate their own lives as creations of God.  I stopped feeling bad about myself and I started to experience the TRUE JOY of being a believer who just so happens to be gay.

cool site Sri Lanka

1/12/2011 5:53:39 PM #

This is my second visit to this blog. We are starting a brand new initiative in the same niche as this blog. Your blog provided us with important information to work on. You have done a fantastic job.

cool site Rwanda

1/12/2011 6:55:55 PM #

It is not mandatory. But if it is there, it would be nice to have such links.

cool site Finland

1/12/2011 6:58:46 PM #

Once I thought about things like: why such information is for free here? Because when you write a book then at least on selling a book you get a percentage. Thank you and good luck on informing people more about it!

cool site Saudi Arabia

1/12/2011 7:08:59 PM #

i know i'm a little off topic, but i just wanted to say i like the layout of your blog. i'm new to the blogegine platform, so any advice on getting my blog looking nice would be appreciated.

cool site Thailand

1/22/2011 11:57:01 PM #

Amazing ideas! I've bookmarked your site and will be back for more. Keep it up. You've got some great information, unlike many other regurgitated and rehashed blogs.

Webdesign United States

3/10/2011 7:36:32 AM #

Hey just testing nice blog thanks

climbing shoes France

3/31/2011 11:12:43 PM #

Women are 37% more likely to go to a psychiatrist than men are.

Cum United States

4/1/2011 9:56:17 AM #

Lucy and Linus (who where brother and sister) had another little brother named Rerun. (He sometimes played left-field on Charlie Brown's baseball team, [when he could find it!]).

Lesbian United States

4/1/2011 11:59:03 AM #

Clans of long ago that wanted to get rid of unwanted people without killing them used to burn their houses down -- hence the expression "to get fired"

Old Grandpa United States

4/1/2011 1:19:12 PM #

American car horns beep in the tone of F.

Young Girl United States

4/2/2011 4:16:26 PM #

can kiss my furry white ass, that little cock monkey is nothing more then a goo guzzling ass clown. The rocket jockey is so f**ked int eh head, I'm not surprised he's a fag, wait, oh yeah! he is. One things for sure though, if he wasn't he'd be hit on by every guy ina gay bar, you know why? because he sucks damnit!!!!!!

Pinoy Online United States

4/2/2011 5:03:47 PM #

The first known contraceptive was crocodile dung, used by Egyptians in 2000 B.C.

Pinoy Online United States

4/4/2011 12:37:20 PM #

A skunk's smell can be detected by a human a mile away.

Ask Pinoy United States

4/4/2011 6:33:55 PM #

The highest point in Pennsylvania is lower than the lowest point in Colorado.

Ask Pinoy United States

4/4/2011 8:16:35 PM #

The average person spends about 2 years on the phone in a lifetime.

Ask Pinoy United States

7/19/2011 12:06:57 PM #

It�s callous to locate knowledgeable people on this field, but you touched remote like you know what you�re talking surrounding! Thanks

casinos en lignes France

7/20/2011 6:15:33 PM #

Thanks , your initiatives are greatly appreciated. I desire you very much accomplishment.

Merrilee Charry United States

7/21/2011 5:37:57 AM #

Why the banner of your blog in inside the category ? Regards, Barbara

video humour France

7/22/2011 7:52:45 AM #

I am often to blogging and i justifiably appreciate your content. The article has emphatically peaks my interest. I am contemporary to bookmark your spot  and mask checking for new information.

casino en lign France

7/24/2011 7:52:22 AM #

Pretty! This was a no kidding wonderful post. Thanks you for your provided information.

casinos en lignes France

7/27/2011 2:11:27 AM #

identical commendable dispatch, i certainly be of importance this website, keep on it

astuce casino France

7/27/2011 3:39:09 AM #

The whole shooting match is bare unenclosed and exceptionally keen explanation of issues. was indeed information. Your website is deeply useful. Thanks in the value of sharing.

casino en lign France

8/28/2011 8:01:48 AM #

Il se pr�sente extr�mement instructif pour moi

riad Marrakech France

9/5/2011 6:00:15 AM #

Lovely blog man, just shared the link with my facebook pals Smile

Carson

9/10/2011 5:34:43 AM #

Surprisingly revealing appreciate it, I do think your followers would possibly want a whole lot more stories along these lines carry on the good effort.

Michael Cole United States

9/14/2011 6:01:56 AM #

Enormously educative bless you, I presume your current audience could quite possibly want way more stories along these lines maintain the excellent effort.

Johnny Marlene United States

9/14/2011 7:50:34 AM #

Exceedingly challenging appreciate it, I do believe your trusty subscribers could very well want more items such as this carry on the excellent hard work.

John Don United States

9/14/2011 12:51:11 PM #

I think else website proprietors should accept this website as an representative , quite unadulterated moreover impressive user cordial diagram. �Grant us a passing postpone urge in all is yet a useless vassal.� by Caecilius Statius.

riad a marrakech France

9/14/2011 1:19:15 PM #

I was looking at quantity of your blog enters on this internet spot plus I understand this snare spot is rattling instructive! Keep posting .

immo Marrakech France

9/14/2011 5:38:04 PM #

Astonishingly helpful many thanks, It looks like your trusty readers would probably want a whole lot more posts such as this carry on the great work.

Johnny Smith United States

9/15/2011 1:44:53 AM #

Extremely entertaining thank you, I reckon your followers would possibly want significantly more reviews like this keep up the excellent hard work.

Gabriel Don United States

9/16/2011 10:52:54 AM #

Hello,

Cool Blog keep it up

Marc

9/20/2011 10:03:24 PM #

It\\\'s awesome Truncation of fields when CSV file is read using ... post, . Thx for your (tips

Alfred Dijon

9/23/2011 5:02:53 AM #

It\\\'s awesome Nishanth&#39;s Blog Thxpost

Alfred Dijon

9/30/2011 2:24:41 PM #

Wow , what an awesome blog. Keep up the good work!

John

10/1/2011 3:10:42 PM #

Let me start by saying nice post. Im not sure if it has been talked about, but when using Chrome I can never get the entire site to load without refreshing many times. Could just be my computer. Thanks.

Automotive Trends

10/1/2011 3:10:42 PM #

Finally, an issue that I am passionate about. I have looked for information of this caliber for the last several hours. Your site is greatly appreciated.

Automotive Trends

10/1/2011 3:10:43 PM #

Thank you for another essential article. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I am on the lookout for such information.

Automotive Trends

10/4/2011 9:33:19 PM #

I genuinely have looking at on this texture scene , it encloses sizzling notifys .

Tayna Naftzinger France

10/18/2011 7:09:23 AM #

Hi
this was a Awesomeartical keep up the good work

mr.dolton mr.kenedy svensson andersson

10/18/2011 9:55:08 AM #

Hi
this was a amazingblog keep up the good work

mr.dolton mr.kenedy svensson andersson

10/22/2011 9:03:08 PM #

It\\\'s amazing Truncation of fields when CSV file is read using ... post, . Thank youpost

Alfred Dijon

11/11/2011 2:07:49 PM #

Hi!, I do  your way you write certain issues in the poker industry. I Will come back in the future. byebye

Pieter

11/12/2011 7:53:31 AM #

I understand you have remarked some very interesting dots , minds for the post.

visite Marrakech France

11/17/2011 2:49:28 AM #

Wohh precisely what I was looking for, esteems for putting up. “The except road of informed a specimen is to dear them without prospect.” by Walter Benjamin.

citee rouge France

11/21/2011 3:27:26 AM #

No need wasting time on exchanging slogans with the temple indoctrinated.

Concha Mader United States

11/22/2011 9:03:31 PM #

I really enjoyed your blog, will share it with my friends, do you have any other content on this subject matter?

bing United States

11/23/2011 11:29:16 AM #

Amazing blog! Do you have any hints for aspiring writers? I'm planning to start my own blog soon but I'm a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I'm totally confused .. Any ideas? Thank you!

Mireille Debartolo United States

11/23/2011 6:21:59 PM #

Magnificent beat ! I wish to apprentice whilst you amend your site, how can i subscribe for a weblog website? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast offered vivid clear idea

Server For Dating United States

11/24/2011 12:45:30 PM #

I have read several good stuff here. Certainly value bookmarking for revisiting. I wonder how a lot attempt you place to create one of these great informative site.

Kaylene Papa United States

11/24/2011 2:17:52 PM #

awesome ^_^

Ann Wolpert United States

11/24/2011 4:31:55 PM #

great post thx

Carline Czapiewski United States

11/25/2011 10:07:43 AM #

I have to say that for the past few of hours i have been hooked by the amazing posts on this website. Keep up the wonderful work.

disposable cell phone United States

11/26/2011 9:44:32 PM #

Hi there, i just wanted to drop you a line to say that i thoroughly enjoyed this detailed post of yours, I have subscribed to your RSS feeds and have skimmed a few of your posts before but this one really stood out for me. I know that I am just a stranger to you but I figured you might appreciate the admiration  Take care  and keep blogging.

Oren Gragson United States

11/27/2011 9:20:16 AM #

Thanks for the good article, I was searching for details like this, going to check out the other posts.

Ina Folds United States

11/29/2011 4:37:51 AM #

Greetings from California! I'm bored at work so I decided to browse your site on my iphone during lunch break. I really like the information you provide here and can't wait to take a look when I get home. I'm surprised at how fast your blog loaded on my mobile .. I'm not even using WIFI, just 3G .. Anyways, fantastic site!

June Fiorenzi United States

11/29/2011 8:16:17 AM #

Thanks for the information?- appreciated?- been studying for awhile, and just wanted to let you know I proceed to enjoy your writing.

Mikki Deblauw United States

11/30/2011 2:30:08 PM #

Trick for making your Screen sharing application go on Steroids

Estella Rowand United States

12/1/2011 10:27:24 AM #

Doug: During a pit stop, the catch can guy holds a can that catches any overflowing gas. The can itself opens a vent that allows the car to be fueled. The can must be inserted during fueling, or NASCAR will penalize the teams. The gas man will hand off the first can to the catch can man, who, once the car is full, will then shake the empty can to signal to the jackman that the car is full and the stop can end. Catch can guys also make most of the wedge and trackbar adjustments, and you will sometimes see them pull tires for the changers.

Jimmy Tarpey United States

12/4/2011 4:14:18 AM #

Jeremy Clarkson says the things that many people think, but only he has the guts to say. What's wrong with that?

Clarkson United States

12/4/2011 4:40:02 AM #

Jeremy Clarkson says the things that many people think, but only he has the guts to say. What's wrong with that?

inurl:Jeremy United States

12/4/2011 5:25:26 PM #

Useful info. Fortunate me I discovered your website by accident, and I'm surprised why this twist of fate did not happened in advance! I bookmarked it.

Delta Dainels United States

12/7/2011 5:03:03 PM #

I just heard "At the end of the day" on AOL Radio. I LIKE IT!!!!!

Jae Dillinger United States

12/9/2011 12:12:58 PM #

I do not even know how I ended up here, but I thought this post was good. I don't know who you are but definitely you're going to a famous blogger if you are not already Cheers!

how to get a woman back United States

12/11/2011 3:27:15 AM #

Sorry, but in this current job market, it is hard to be optimistic if you're a woman over 50. Age discrimination is also almost impossible to prove since the employer can use other reasons not to hire us. I am looking for solutions and I don't see any. The non-profits as some suggested msy not be an organization that some cannot identify with. Are we going to have to start taking scrub women jobs or be nannies??? Unless you have the resources to start your won business (which I don't) you're screwed.

Gretta Coplon United States

12/18/2011 7:11:48 PM #

my own blogroll.

admin

12/20/2011 12:18:04 PM #

Fantastic and it's free? Thanks ever so much, I have been struggling for several months and getting nowhere fast. The Sakura Project looks like exactly what I need.

Catrina Kogen United States

12/22/2011 4:36:56 AM #

Are you winner? I\'ve always dreamed of winning the lottery. Get tickets for lottereynye a few pieces a week, and never won! BUT I bought a ticket online lotto and win $ 1800 - and was very happy! You never know where you win.

XluckWinnerz

1/6/2012 8:51:43 PM #

They always have cute kids gardening stuff. A lot of indie garden centers don t carry garden tools and stuff just for kids.

the lesbian sex archives United States

1/7/2012 5:07:42 AM #

Top quality and also handful regarding hyperlinks for you to your website can boost your own seek engine position speedily.

senuke discount United States

1/10/2012 5:03:00 AM #

Surprisingly challenging cheers, It looks like your trusty subscribers would possibly want a good deal more content of this nature carry on the great effort.

Roseanna Rosette United States

1/11/2012 4:51:58 PM #

Don  When IBM first produced CRT terminals for their computers, they put a little clicker in the keyboard so it would make a clicking noise every time a key was pressed because the people who moved from typewriters to terminals were disconcerted by the quiet keyboards. True story.

Mireille Haufler United States

1/16/2012 10:01:35 PM #

Cet blog est impressionnant et je viens d'ailleurs le signaler � une coll�gue qui semble �tre du m�me avis que vous et je suis convaincue qu'elle m'en remerciera. Soyez remerciez pour ce billet et l'implication pour partager ces opinions. Je serais enchant�e d'avoir l'opportunit� de lire vos billets sur ce th�me prochainement. Ca m'est extr�mement pr�cieux ! Merci 1000 fois !

sondage pr�sidentielles France

1/22/2012 4:31:55 AM #

Unfair comparison, since Germany and Japan have national health care systems.

Romona Calderaro United States

1/25/2012 1:59:40 PM #

My current reading is for official reviews, but reading others work always inspires me, moves me to want to improve myself. I can remember when it was a negative, giving me thoughts about how I'd never get there.

china daily news United States

1/26/2012 5:05:30 PM #

No word that this control can be disabled by smart kids within 5 minutes using youtube Microsoft made it too easy ...

Leighann Seiwell United States

1/28/2012 4:23:12 PM #

Thanks for your article, this is the article that I looking for all day for my students learning buddy,and you solved my problem, once again thanks

Danelle Graciano United States

1/31/2012 12:00:18 PM #

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! Keep up the good work.

Automotive Trends

2/2/2012 9:22:47 AM #

Defqst1 United States

Add comment




  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen


About Me

Nishanth Nair  

 A die hard fan of Rise of Nations... I write few softwares for McAfee Inc. for a living.

 

Portfolio:

http://morningbellnews.com
TheXorb.com
http://Necab.org
http://SufiKatha.com
http://DeepaRecipes.com
http://ManipalFoundation.in
http://NetraArts.com
http‌://EnWebTech.com 

http://homeopathyinchicago.com/


Contact : Nair.Nishanth@Gmail.com 

 

All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer.

Tag cloud

free counters