Page 1 of 1

.CSV file to Access Database

Posted: October 2nd, 2008, 3:16 pm
by husain77
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(); }

.CSV file to Access Database

Posted: October 2nd, 2008, 4:21 pm
by Yossarian22
Use Perl DBI its beautifully simple.

.CSV file to Access Database

Posted: October 2nd, 2008, 4:47 pm
by husain77
Do you have a sample for that ? I guess i can invoke perl scripts through a C# executable.

.CSV file to Access Database

Posted: October 2nd, 2008, 7:28 pm
by ArifJaffer
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

.CSV file to Access Database

Posted: October 6th, 2008, 3:28 pm
by husain77
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 .