SQL SELECT语句使用多个参数并拉出特定列

时间:2017-09-26 21:33:18

标签: sql vb.net

我需要帮助弄清楚如何使用从多个SELECT中选择的多个参数来编写listboxes语句。然后,我需要处理该行并将特定列返回到textboxes

我要做的是在第一个listbox填充父项列表,然后再使用三个listboxes,我向下钻取到特定部分,然后填写textboxes与最终选择的位置。

到目前为止我所拥有的是:

Private Sub GetPartDetails(ParentDesc As String, Description1 As String, Description2 As String, Description3 As String)

        SQL.AddParameter("@ParentDesc", ParentDesc)
        SQL.AddParameter("@Description1", Description1)
        SQL.AddParameter("@Description2", Description2)
        SQL.AddParameter("@Description3", Description3)

        SQL.ExecQuery("SELECT TOP 1 * FROM PartsListMenu WHERE ParentItem = @ParentDesc AND FirstDescriptor = Description1 AND SecondDescriptor = @Description2 AND ThirdDescriptor = Descriptor3;")


        For Each x As DataRow In SQL.DataBDataT.Rows

            txtCabinet.Text = x("Cabinet")
            txtDrawer.Text = x("Drawer")
            txtRow.Text = x("Row")
            txtSlot.Text = x("Slot")
            txtQuantity.Text = x("Quantity")
        Next

    End Sub

以下是我根据四个listboxes中选择的内容调用上述代码的地方。

Private Sub lbThirdDescriptor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lbThirdDescriptor.SelectedIndexChanged
            txtCabinet.Clear()
            txtDrawer.Clear()
            txtRow.Clear()
            txtSlot.Clear()
            GetPartDetails(lbParentItem.Text, lbFirstDescriptor.Text, lbSecondDescriptor.Text, lbThirdDescriptor.Text)
End Sub

listboxes功能正常,我已验证每个说明参数都包含正确的listbox选项,但当我选择最后一个listbox时,textboxes不会填充有什么。如果我将SELECT语句缩小到一个参数,它会在textboxes中填入所选listbox中相应项目的正确位置信息。

2 个答案:

答案 0 :(得分:0)

不确定您的实际代码中是否存在拼写错误,或者只是在此处的问题中,但

 count = ll.getChildCount();

应该是

    SQL.ExecQuery("SELECT TOP 1 * FROM PartsListMenu WHERE ParentItem = @ParentDesc AND FirstDescriptor = Description1 AND SecondDescriptor = @Description2 AND ThirdDescriptor = Descriptor3;")

答案 1 :(得分:0)

很抱歉将此添加为答案,但我没有足够的评论意见。如果您只选择Top 1,为什么选择循环?你能检查一下SQL.DataBDataT.Rows.Count看看你是否有任何行?不知道这是什么技术,但有时你必须先移动才能获得数据。