0

我的程序中有一个充满计算 的ComboBox名称(例如 Current_Ratio、Total_Debt_To_Assets_Ratio)。实际上是通过使用我的 Access 数据库中调用的表中的字段内容来填充的。ComboBox_CalculationsComboBox_CalculationsCriteria

我需要创建一个名为Calculations_Quarterly. 查询需要有 , 的字段,Ticker然后. 中的每个项目都有一个字段。所以对于这个例子,我还需要名为and的字段。 [Year]PeriodComboBox_CalculationsCurrent_RatioTotal_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
4

1 回答 1

1

我找不到你的组合框的名称或它是如何填充的,所以假设它是命名Combo1的,并且你使用它填充它Combo1.Items.Add("..."),你会想要这样的东西:

Dim sb as new System.Text.StringBuilder("")
For each s as string in Combo1.Items
  sb.Append("," & s)
Next

然后在你的 SQL 中:

Dim cmd2 As OleDbCommand = New OleDbCommand("CREATE PROC " & Calculation & " AS SELECT Income_Statements.Ticker, Income_Statements.[Year], Income_Statements.Period, " & Formula & " AS " & Calculation & sb.ToString & " 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)
于 2013-10-18T18:05:59.970 回答