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(); }