我在 Visual Studio 中设置了一个连接到 SQL Server 数据库的表适配器。我已按照 MSDN 教程进行操作,并为此 TA 手动设置了一些查询。我认为这些查询是“pre_hardcoded”。我使用默认代码调用这些查询:
Me.ItemFactTableAdapter.My_Pre_Hardcoded_Query(Me.MasterDataSet.ItemFact)
我想动态调用不同配置中的数据(来自同一个主表),因此我需要很多这些预硬编码的查询。所以,我不想写 1k 个查询,而是想使用这样的东西:
TableName = "ItemFact"
H_Label = "ChainName"
V_Label = "ItemName"
Dim Measure As String = "Volume"
Dim Select_Clause As String = "select distinct " & H_Label & "," & V_Label & ", Sum(" & Measure & ") as " & Measure & " "
Dim From_Clause As String = "from " & TableName & " "
Dim Where_Clause As String = ""
Dim GroupBy_Clause As String = "group by " & H_Label & "," & V_Label
Dim SelectionQuery = Select_Clause & From_Clause & Where_Clause & GroupBy_Clause
我可以在其中动态更新“测量”和“H”和“V 标签”的值。问题是:如何声明此 SelectionQuery 为 TA 的有效部分,以便我可以像这样使用它:
Me.ItemFactTableAdapter.SelectionQuery (Me.MasterDataSet.ItemFact)