User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,426 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,020 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 18960 | Replies: 4
Reply
Join Date: Jan 2006
Posts: 2
Reputation: sseo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sseo sseo is offline Offline
Newbie Poster

Reading CSV file into a ADO recordset

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Reading CSV file into a ADO recordset

  #2  
Jan 25th, 2006
c# code
using System.Data;

//in some function
System.Data.Odbc.OdbcConnection conn;
DataTable dt;
System.Data.Odbc.OdbcDataAdapter da;
string connectionString;
string importFolder;
string fileName;

importFolder = @"c:\importfile" //or pass it in -this is the folder in which the csv file is in

fileName = "csvimport.csv" //or pass it in -this is the csv file to be imported

connectionString= @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";";
conn = new Odbc.OdbcConnection(connectionString)

//we only pass it the folder.  The csv file import is in the query which follows

da = new System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn);
da.Fill(dt);

//Your table is filled and uses the first row of the csv file as the column headings.

Hope it helps
Reply With Quote  
Join Date: Jan 2006
Posts: 2
Reputation: sseo is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sseo sseo is offline Offline
Newbie Poster

Re: Reading CSV file into a ADO recordset

  #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  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Reading CSV file into a ADO recordset

  #4  
Jan 26th, 2006
I will change it to vb but bear with me as my vb is rusty to say the least.
imports System.Data;

//in some function
Dim conn As System.Data.Odbc.OdbcConnection 
Dim dt As DataTable
Dim da As System.Data.Odbc.OdbcDataAdapter;
Dim connectionString As string
Dim importFolder As string
Dim fileName As string

importFolder = "c:\importfile" //or pass it in -this is the folder in which the csv file is in

fileName = "csvimport.csv" //or pass it in -this is the csv file to be imported

connectionString= "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";"
conn = new Odbc.OdbcConnection(connectionString)

//we only pass it the folder.  The csv file import is in the query which follows

da = new System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn);
da.Fill(dt);

//Your table is filled and uses the first row of the csv file as the column headings.
Reply With Quote  
Join Date: Feb 2006
Posts: 1
Reputation: Romulinho is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Romulinho Romulinho is offline Offline
Newbie Poster

Re: Reading CSV file into a ADO recordset

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

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC