我有一个启用了milti select的列表框,我试图根据所选的值创建一个TSQL命令,我从列表框中获取第一个选定的值,我如何获得其余的选定值。
Private Sub createSQLCMD(ByVal strServerName As String, ByVal
strDatabaseName As String, ByVal strTableName As String)
Dim strSQLCMD As String = "SELECT "
For i As Integer = 0 To lstFieldList.Items.Count - 1
If (lstFieldList.GetSelected(i)) And i < lstFieldList.Items.Count - 1 Then
strSQLCMD &= lstFieldList.SelectedValue.ToString & ","
End If
Next
strSQLCMD &= lstFieldList.SelectedValue.ToString
txtSQLCMD.Text = strSQLCMD & " FROM " & strTableName
End Sub
答案 0 :(得分:0)
Private Sub createSQLCMD(ByVal strServerName As String, ByVal strDatabaseName As String, ByVal strTableName As String)
Dim strSQLCMD As String = "SELECT "
Dim selectedItems = lstFieldList.SelectedItems.Cast(Of String)
'Dont forget to check if no item selected else you'll get an error.
txtSQLCMD.Text = strSQLCMD & String.Join(",", selectedItems) & " FROM " & strTableName
End Sub