942,790 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 49052
  • ASP.NET RSS
Jan 25th, 2006
0

Reading CSV file into a ADO recordset

Expand Post »
I'm relatively new to programming.

Problem:
I'm creating an ASP.NET app the needs to read a CSV file and filter the data.

I searched the net and only found classic ASP examples or all DB driven examples.

Does anyone have sample code. Or is there any other suggestions on how to read and filter. Thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sseo is offline Offline
2 posts
since Jan 2006
Jan 25th, 2006
0

Re: Reading CSV file into a ADO recordset

c# code
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. using System.Data;
  3.  
  4. //in some function
  5. System.Data.Odbc.OdbcConnection conn;
  6. DataTable dt;
  7. System.Data.Odbc.OdbcDataAdapter da;
  8. string connectionString;
  9. string importFolder;
  10. string fileName;
  11.  
  12. importFolder = @"c:\importfile" //or pass it in -this is the folder in which the csv file is in
  13.  
  14. fileName = "csvimport.csv" //or pass it in -this is the csv file to be imported
  15.  
  16. connectionString= @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";";
  17. conn = new Odbc.OdbcConnection(connectionString)
  18.  
  19. //we only pass it the folder. The csv file import is in the query which follows
  20.  
  21. da = new System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn);
  22. da.Fill(dt);
  23.  
  24. //Your table is filled and uses the first row of the csv file as the column headings.

Hope it helps
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Jan 26th, 2006
0

Re: Reading CSV file into a ADO recordset

Thanks for the code f1_fan.

I'll try to work with the code.

Does anyone have a VB example as well.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sseo is offline Offline
2 posts
since Jan 2006
Jan 26th, 2006
0

Re: Reading CSV file into a ADO recordset

I will change it to vb but bear with me as my vb is rusty to say the least.
ASP.NET Syntax (Toggle Plain Text)
  1. imports System.Data;
  2.  
  3. //in some function
  4. Dim conn As System.Data.Odbc.OdbcConnection
  5. Dim dt As DataTable
  6. Dim da As System.Data.Odbc.OdbcDataAdapter;
  7. Dim connectionString As string
  8. Dim importFolder As string
  9. Dim fileName As string
  10.  
  11. importFolder = "c:\importfile" //or pass it in -this is the folder in which the csv file is in
  12.  
  13. fileName = "csvimport.csv" //or pass it in -this is the csv file to be imported
  14.  
  15. connectionString= "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";"
  16. conn = new Odbc.OdbcConnection(connectionString)
  17.  
  18. //we only pass it the folder. The csv file import is in the query which follows
  19.  
  20. da = new System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn);
  21. da.Fill(dt);
  22.  
  23. //Your table is filled and uses the first row of the csv file as the column headings.
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006
Feb 7th, 2006
0

Re: Reading CSV file into a ADO recordset

Can I access a remote csv? Example: http://www.domain.com/file.csv
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Romulinho is offline Offline
1 posts
since Feb 2006
Apr 20th, 2010
0

Thanks for the post

Thank you for the code, it really helped me

Click to Expand / Collapse  Quote originally posted by f1 fan ...
c# code
ASP.NET Syntax (Toggle Plain Text)
  1.  
  2. using System.Data;
  3.  
  4. //in some function
  5. System.Data.Odbc.OdbcConnection conn;
  6. DataTable dt;
  7. System.Data.Odbc.OdbcDataAdapter da;
  8. string connectionString;
  9. string importFolder;
  10. string fileName;
  11.  
  12. importFolder = @"c:\importfile" //or pass it in -this is the folder in which the csv file is in
  13.  
  14. fileName = "csvimport.csv" //or pass it in -this is the csv file to be imported
  15.  
  16. connectionString= @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";";
  17. conn = new Odbc.OdbcConnection(connectionString)
  18.  
  19. //we only pass it the folder. The csv file import is in the query which follows
  20.  
  21. da = new System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn);
  22. da.Fill(dt);
  23.  
  24. //Your table is filled and uses the first row of the csv file as the column headings.

Hope it helps
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wakamohle is offline Offline
1 posts
since Apr 2010
Apr 21st, 2010
0
Re: Reading CSV file into a ADO recordset
You're welcome.

I'm glad you found it useful. Please read member rules - http://www.daniweb.com/forums/faq.ph...niweb_policies

Thread Closed.
Last edited by adatapost; Apr 21st, 2010 at 8:53 am.
Moderator
Reputation Points: 2134
Solved Threads: 1226
Posting Genius
adatapost is offline Offline
6,523 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in ASP.NET Forum Timeline: HTTP Error 403 on clicking LinkButton to open PDF file
Next Thread in ASP.NET Forum Timeline: btnLogin and Create Userprofiles





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC