【发布时间】:2022-11-01 21:37:14
【问题描述】:
我试图在运行时加载一个带有值的复选框。但是当我尝试从中获取检查值时。它返回以下错误:
未为字符串 '' 和类型 'DataRowView' 定义运算符 '&',
虽然当我在设计时加载选中列表框时它工作正常
Public Sub loadListBox(ByVal lst As CheckedListBox, ByVal sql As String, ByVal fldDsp As String, ByVal fldVal As String) Try 'open DB Connection openConn() Dim lstDS As New DataTable Dim lstAD As SqlDataAdapter Dim cboCMD As New SqlCommand(sql, Qconn) lstAD = New SqlDataAdapter(sql, Qconn) lstAD.Fill(lstDS) lst.Items.Clear() lst.SelectedIndex = -1 With lst .Items.Clear() .DataSource = Nothing .Text = fldDsp .DataSource = lstDS .ValueMember = fldVal .DisplayMember = fldDsp End With Catch ex As Exception msgError("ERROR:Failed Loading Values " + ex.Message) Exit Sub Finally closeConn() End Try End Sub---on form load Dim symp As String = "SELECT distinct facility FROM [eLab].[settings].[Locations]" frm.chk_locations.Items.Clear() loadListBox(frm.CheckedListBox1, symp, "facility", "facility")Public Function getCheckedItems(ByVal chk As CheckedListBox) As String Dim items As String = "" If chk.CheckedItems.Count > 0 Then items = "" & chk.CheckedItems(0) & "" 'check if the checked items are more than 1 If chk.CheckedItems.Count > 1 Then For i As Integer = 1 To chk.CheckedItems.Count - 1 items = items & "," & chk.CheckedItems(i) & "" Next End If End If Return items End FunctionDim configlocation As String = getCheckedItems(frm.CheckedListBox1) msgBox(configlocation)我期待的是位置,位置 X(所有选定的位置以逗号分隔
【问题讨论】:
标签: sql-server vb.net