I have two Microsoft Access database tables. They are named Historical_Stock_Prices and Balance_Sheets. I need to combine data from each of these tables to create a table called Daily. I need to take the fields Ticker, [Date], and [Close] from Historical_Stock_Prices and I need to take the field Common_Stocks from Balance_Sheets.
I will not be taking every row from the Historical_Stock_Prices and Balance_Sheets though. I will only be taking the rows that are on or before a date selected in a DateTimePicker named dtpDateSelection.
Now the main problem that I have is that Historical_Stock_Prices contains a row for each day. While Balance_Sheets contains a row for each quarter. So for each day in a quarter the figure that comes from Balance_Sheets will be the same.
Here is the code that I have so far:
Dim Date1 As Date = dtpDateSelection.Value
Try
Dim cmd As OleDbCommand = New OleDbCommand("CREATE PROC Daily AS SELECT [H].[Ticker], [H].[Date], [H].[Close], [B].[Common_Stocks] FROM [Historical_Stock_Prices] AS [H] INNER JOIN [Balance_Sheets] AS [B] ON Int(Year([H].[Date])) = Int([B].[Year]) AND Int(Format([H].[Date],'Q')) = Int([B].[Period]) AND CStr([H].[Ticker]) = CStr([B].[Ticker]) WHERE CDate([H].[Date]) = #" & CDate(Date1) & "#", con)
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
Dim cmda As OleDbCommand = New OleDbCommand("DROP PROCEDURE Daily", con)
cmda.ExecuteNonQuery()
Dim cmdb As OleDbCommand = New OleDbCommand("CREATE PROC Daily AS SELECT [H].[Ticker], [H].[Date], [H].[Close], [B].[Common_Stocks] FROM [Historical_Stock_Prices] AS [H] INNER JOIN [Balance_Sheets] AS [B] ON Int(Year([H].[Date])) = Int([B].[Year]) AND Int(Format([H].[Date],'Q')) = Int([B].[Period]) AND CStr([H].[Ticker]) = CStr([B].[Ticker]) WHERE CDate([H].[Date]) = #" & CDate(Date1) & "#", con)
cmdb.ExecuteNonQuery()
End Try
This code creates the table Daily and the fields Ticker, [Date], [Close] and Common_Stocks within that table. But the code does not load any data into the rows of the table. Any ideas why not?
New OleDbCommand("SELECT [H].[Ticker], ....and use a DataAdapter to fill a DataTable