我的程序中有一个充满计算 的ComboBox
名称(例如 Current_Ratio、Total_Debt_To_Assets_Ratio)。实际上是通过使用我的 Access 数据库中调用的表中的字段内容来填充的。ComboBox_Calculations
ComboBox_Calculations
Criteria
我需要创建一个名为Calculations_Quarterly
. 查询需要有 , 的字段,Ticker
然后. 中的每个项目都有一个字段。所以对于这个例子,我还需要名为and的字段。 [Year]
Period
ComboBox_Calculations
Current_Ratio
Total_Debt_To_Assets_Ratio
这是我的表格到目前为止的样子:
Criteria
Calculations_Quarterly
这是我一次添加一个字段的代码(在这种情况下Current_Ratio
。但我不知道如何为每个项目添加一列ComboBox_Calculations
con.Open()
Dim dr As OleDbDataReader
Dim cmd6 As New OleDb.OleDbCommand("SELECT Calculation, [Interval], Formula FROM Criteria", con)
dr = cmd6.ExecuteReader
dr.Read()
Dim Calculation = dr("Calculation").ToString
Dim Interval = dr("Interval").ToString
Dim Formula = dr("Formula").ToString
Dim Where_Statement As String
If Interval = "Daily" Then
Where_Statement = "WHERE Historical_Stock_Prices.[Date] < " & DateTime.Now.Date & ""
ElseIf Interval = "MRQ" Then
Where_Statement = "WHERE Income_Statements.Period < 5"
ElseIf Interval = "TTM" Then
Where_Statement = "WHERE Income_Statements.Period < 5"
ElseIf Interval = "5 Year" Then
Where_Statement = "WHERE Income_Statements.Period = 5"
Else
Where_Statement = ""
End If
Try
Dim cmd2 As OleDbCommand = New OleDbCommand("CREATE PROC " & Calculation & " AS SELECT Income_Statements.Ticker, Income_Statements.[Year], Income_Statements.Period, " & Formula & " AS " & Calculation & " FROM Income_Statements INNER JOIN Balance_Sheets ON (Income_Statements.Ticker = Balance_Sheets.Ticker) AND (Income_Statements.[Year] = Balance_Sheets.[Year]) AND (Income_Statements.Period = Balance_Sheets.Period)" & Where_Statement & "", con)
cmd2.ExecuteNonQuery()
Catch ex As Exception
Finally
Dim cmd2a As OleDbCommand = New OleDbCommand("DROP PROCEDURE " & Calculation & "", con)
cmd2a.ExecuteNonQuery()
Dim cmd2b As OleDbCommand = New OleDbCommand("CREATE PROC " & Calculation & " AS SELECT Income_Statements.Ticker, Income_Statements.[Year], Income_Statements.Period, " & Formula & " AS " & Calculation & " FROM Income_Statements INNER JOIN Balance_Sheets ON (Income_Statements.Ticker = Balance_Sheets.Ticker) AND (Income_Statements.[Year] = Balance_Sheets.[Year]) AND (Income_Statements.Period = Balance_Sheets.Period)" & Where_Statement & "", con)
cmd2b.ExecuteNonQuery()
End Try
con.Close