Reading CSV file into a ADO recordset

Reply

Join Date: Jan 2006
Posts: 2
Reputation: sseo is an unknown quantity at this point 
Solved Threads: 0
sseo sseo is offline Offline
Newbie Poster

Reading CSV file into a ADO recordset

 
0
  #1
Jan 25th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Reading CSV file into a ADO recordset

 
0
  #2
Jan 25th, 2006
c# code
  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 2
Reputation: sseo is an unknown quantity at this point 
Solved Threads: 0
sseo sseo is offline Offline
Newbie Poster

Re: Reading CSV file into a ADO recordset

 
0
  #3
Jan 26th, 2006
Thanks for the code f1_fan.

I'll try to work with the code.

Does anyone have a VB example as well.
Is cable or satellite cheaper? - satellite tv dish provider
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Reading CSV file into a ADO recordset

 
0
  #4
Jan 26th, 2006
I will change it to vb but bear with me as my vb is rusty to say the least.
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 1
Reputation: Romulinho is an unknown quantity at this point 
Solved Threads: 0
Romulinho Romulinho is offline Offline
Newbie Poster

Re: Reading CSV file into a ADO recordset

 
0
  #5
Feb 7th, 2006
Can I access a remote csv? Example: http://www.domain.com/file.csv
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 30613 | Replies: 4
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC