Serving the Quantitative Finance Community

 
User avatar
husain77
Topic Author
Posts: 0
Joined: December 12th, 2007, 9:00 pm

.CSV file to Access Database

October 2nd, 2008, 3:16 pm

Has anyone tried to do a import of a .csv file to an acess database in .NET ( C#, C++ , VB etc) I am trying to write a piece of software which when giving the name of the symbol gets the historical data from Yahoo , which is in .csv format and store it as a table in access . If anybody has done anything similar . Can you post your code here ? Below is what i have written in C# for reading the .csv file in to .NET structures . Upon reading this .csv data i need to create a Table for MSFT in Acess and then add the prices . And i am struggling with that piece . Can anyone help ? string CompleteFile_name = @"C:\\CSV\\MSFT.csv"; string pathName = System.IO.Path.GetDirectoryName(CompleteFile_name); string file = System.IO.Path.GetFileName(CompleteFile_name); OleDbConnection excelConnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathName + ";Extended Properties=Text;"); OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM [" + file+"]", excelConnection); OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand); excelConnection.Open(); DataSet ds = new DataSet(); excelAdapter.Fill(ds,"MSFT"); DataTable dt = ds.Tables["MSFT"]; foreach (DataRow row in dt.Rows) { foreach (DataColumn col in dt.Columns) { Console.Write(row[col]); Console.Write(" "); } Console.WriteLine(); }
 
User avatar
Yossarian22
Posts: 4
Joined: March 15th, 2007, 2:27 am

.CSV file to Access Database

October 2nd, 2008, 4:21 pm

Use Perl DBI its beautifully simple.
 
User avatar
husain77
Topic Author
Posts: 0
Joined: December 12th, 2007, 9:00 pm

.CSV file to Access Database

October 2nd, 2008, 4:47 pm

Do you have a sample for that ? I guess i can invoke perl scripts through a C# executable.
 
User avatar
ArifJaffer
Posts: 0
Joined: June 24th, 2008, 9:45 pm

.CSV file to Access Database

October 2nd, 2008, 7:28 pm

one of the fastest - though not the safest as there is generally no type checking ways of doing this is something called bcpThere should be a bcp utility on your installation that does bulk copy insertsAlso if you want to improve performance and future scalability consider avoiding MS access it is not the best product to use especially given that faster DB's like mySQL exist and are now free
 
User avatar
husain77
Topic Author
Posts: 0
Joined: December 12th, 2007, 9:00 pm

.CSV file to Access Database

October 6th, 2008, 3:28 pm

Thanks for the suggestion for migrating to a different database. I ended up installing mySql free version and was able to do the fetching of data from .csv in to the database. Its a breeze . Although i felt the query time was slower than MS access. I might have to play around with some settings in the database. Thanks .