0

我正在尝试根据来自选中列表框的用户输入执行 SQL 选择查询。我能够找到一些代码,但该解决方案似乎不起作用。在调试时,它一直在第 3 行出现问题,我不知道为什么。

任何帮助将不胜感激。

Dim DistrictString As StringBuilder = New StringBuilder()
    For h = 0 To Me.District.CheckedItems.Count - 1
        If Me.District.CheckedItems(h).Selected Then
            DistrictString.Append(Me.District.CheckedItems(h).Value & ",")
        End If
    Next

有了一些建议,这里是新编辑的代码版本,它现在在 Append 行上崩溃了。

新错误是“未找到类型“字符串”的公共成员“值”

Dim DistrictW As String
Dim DistrictX As String
Dim DistrictString As StringBuilder = New StringBuilder
    For h = 0 To Me.District.CheckedItems.Count - 1
        DistrictString.Append(Me.District.CheckedItems(h).Value & ",")
    Next
DistrictW = DistrictString.ToString
DistrictX = DistrictW.Substring(0, DistrictString.Length - 1)
4

3 回答 3

0

由于看起来您正在创建一个类似...xyz in ('a', 'b', 'c', 'd')...以下代码的表达式,因此可能更合适:

对于 h = 0 对于 Me.District.CheckedItems.Count - 1

       DistrictString += "'" & Me.District.CheckedItems(h).Value & "',"

下一个

DistrictString = DistrictString.Substring(0, DistrictString.Length - 1)

完全搞乱 .SELECTED 属性是没有意义的。选中的所有内容都是为了您的目的而“选择”的。

于 2013-06-18T03:24:55.263 回答
0
If Me.District.CheckedItems.Items(h).Selected Then

     DistrictString.Append(Me.District.CheckedItems.Items(h).Value & ",")

End If

使用 CheckboxList.Items

于 2013-06-17T21:25:13.063 回答
0

感谢所有帮助过的人,这是我实施的解决方案

从这个小练习中学到了很多东西。

Dim DistrictW As String
Dim DistrictX As String
Dim DistrictString As StringBuilder = New StringBuilder
    For h = 0 To Me.District.CheckedItems.Count - 1
        DistrictString.Append(Me.District.CheckedItems(h).ToString & ",")
    Next
DistrictW = DistrictString.ToString
DistrictX = DistrictW.Substring(0, DistrictString.Length - 1)
于 2013-06-18T17:12:24.737 回答