jaya sanala

jaya sanala

  • NA
  • 1
  • 0

reading an excel file in c#

Jun 23 2009 3:43 PM
Hi,
i m Jay working for USDA in Kansas city, KS. i m working on project where i need to upload an excel file which is actually a CSV file with column headers. on upload button click  i need to read each row and depending on some perticular value in each row i have to insert that row into 3 different tables(depending on the value) in database.
so i need to check the columns first to see if any of the columns are missing, then i need to read each row and while reading each row i need to check if cofips is 999 and district is 99 then i have to insert that row in one table, if cofips is 999 and district is not 99 then in to another table and if cofips is not 999 and district is not 99 then into a different table ( u can see in below data).
i m using ASP.net as front end and C# as back end and Microsoft enterprise library to connect to Database.
please anyone help me with the sample code ...i have been struck with this for the past 2 days in my work.
below is the sample CSV file which is actually in Excel file. please replay me back  to my mail id: [email protected]
 
croptypeyearstatecntystfipsCRDcofipscommcodepracplntplntharvharv[lnyldharyldyldunitprodprodunit
1079971993WAall5399999099720000500LBS10000000LBS
1079971994WAall5399999099717000559LBS9500000LBS
1079971995WAall5399999099715000580LBS8700000LBS
1079971996WAall5399999099713000685LBS8900000LBS
1079971997WAall5399999099713000769LBS10000000LBS
1079971998WAall5399999099718000778LBS14000000LBS
1079971999WAall5399999099719000716LBS13600000LBS
1079972000WAall5399999099717000794LBS13500000LBS
1079972001WAall5399999099714500793LBS11500000LBS
1079972002WAall5399999099712000858LBS10300000LBS
1079972003WAall5399999099712500816LBS10200000LBS
1079971993WAall532199909971500533LBS800000LBS
1079971994WAall532199909971500567LBS850000LBS
1079971995WAall532199909971500560LBS840000LBS
1079971996WAall532199909971000750LBS750000LBS
1079971997WAall53219990997900767LBS690000LBS
1079971998WAall532199909971000610LBS610000LBS
1079971999WAall532199909971000630LBS630000LBS
1079972000WAall532199909971000700LBS700000LBS
1079972001WAall53219990997700714LBS500000LBS
1079972002WAall53219990997900722LBS650000LBS
1079972003WAall53219990997700786LBS550000LBS
1079971993WAall532599909974000625LBS2500000LBS
1079971994WAall532599909973500714LBS2500000LBS
1079971995WAall532599909974300674LBS2900000LBS
1079971996WAall532599909974500733LBS3300000LBS
1079971997WAall532599909974700651LBS3060000LBS
1079971998WAall532599909976000638LBS3830000LBS
1079971999WAall532599909975500655LBS3600000LBS
1079972000WAall532599909975000800LBS4000000LBS
1079972001WAall532599909974500800LBS3600000LBS
1079972002WAall532599909973400838LBS2850000LBS
1079972003WAall532599909974500778LBS3500000LBS
1079971993WAall5371999099713000438LBS5700000LBS
1079971994WAall5371999099710500490LBS5150000LBS
1079971995WAall537199909978000525LBS4200000LBS
1079971996WAall537199909976300619LBS3900000LBS
1079971997WAall537199909975800828LBS4800000LBS
1079971998WAall537199909979200922LBS8480000LBS
1079971999WAall5371999099711000765LBS8410000LBS
1079972000WAall5371999099710000810LBS8100000LBS
1079972001WAall537199909978300819LBS6800000LBS
1079972002WAall537199909976400922LBS5900000LBS
1079972003WAall537199909976000892LBS5350000LBS
1079971993WAall537799909971000700LBS700000LBS
1079971994WAall537799909971000800LBS800000LBS

Answers (2)