I need to parse and import a .csv file to a MS SQL database. Here is a sample of the .CSV file:
Symbol,Date,Open,High,Low,Close,Volume
AACC,15-Jan-13,4.53,4.56,4.5,4.53,23600
AAIT,15-Jan-13,28.35,28.57,27.94,28.25,4900
AAME,15-Jan-13,3.25,3.3,3.23,3.25,3700
AAON,15-Jan-13,22.5,22.75,22.21,22.31,33300
AAPL,15-Jan-13,498.3,498.99,483.38,485.92,31313200
AAWW,15-Jan-13,43.96,44.24,42.73,43.36,345800
So the first row contains the headers, and the next the data. The columns are always the same, they don't change from one file to the next. I need to have a program that will take the files and import them in an SQL database. The requirements are as follows:
1) There must be a table per unique symbol. In this case one for AACC, one for AAIT, one for AAME, etc. If the program sees a symbol for which a table doesn't exist, it must create the [login to view URL], if there already is a table for that symbol only an insert is necessary.
2) The format for each table is as follows:
CREATE TABLE [dbo].[AAPL](
[Symbol] [varchar](20) NOT NULL,
[Index] [bigint] NOT NULL,
[Open] [float] NOT NULL,
[High] [float] NOT NULL,
[Low] [float] NOT NULL,
[Close] [float] NOT NULL
) ON [PRIMARY]
3) The column INDEX is derived from Date. Here is the code I'm using now:
DateTime dt = [login to view URL](csv[DATEFIELD])
static int ConvertDateToBarNumber(DateTime dt)
{
/*
* Defines a unique index for each minute, starting on 2000/1/1 00:00
*/
return ([login to view URL] - 2000) * 525949 + [login to view URL] * 43829 + [login to view URL] * 1440 + [login to view URL] * 60 + [login to view URL];
}
This is basically the number of minutes elapsed since 1/1/2000
4) This should be a console application, not windows forms. I would like to specify only the folder where the .csv files are located, and the program will automatically process all .csv files in the folder. I would also like to have an option to DELETE the file after it is processed.