Hi,
I think you are not properly concatenating the string.ICan you post code you
are using for concatenating the string.It should be something like this:
Code for with Single Quotes:
For i As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected Then
strselecteditems = strselecteditems & "'" & ListBox1.Items(i).Text &
"','"
strselecteditems = strselecteditems.Substring(strselecteditems.Length - 2)
End If
Next
Code for without Single Quotes:
For i As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected Then
strselecteditems = strselecteditems & ListBox1.Items(i).Value & ","
strselecteditems = strselecteditems.Substring(strselecteditems.Length - 1)
End If
Next
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.
"BigSam" wrote:
I added a textbox control & populated it with the selected values. I tried
using values with & without single quotes, neither worked. My query is using
the IN operator & works well (without the quotes) when only one item is
selected.
"Manish Bafna" wrote:
Hi,
You can loop through all selected items of listbox and append it to
string.Then you can assign that string to sql datasource.Something like this:
Dim strselecteditems As String
For i As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.Items(i).Selected Then
strselecteditems = strselecteditems & ListBox1.Items(i).Text
End If
Next
Thereafter set the SQL Data Source to string strselecteditems
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.
"BigSam" wrote:
I've a ListBox with the Selection Mode set to Multiple. I want to use the
Selected values as the WHERE Parameters in a SQL Data Source.
If I set the SQL Data Source to use the Selected Value of the Control, only
the 1st selected value is used.
If I build a TextBox with the selected values & use that as the Parameters
Control, I get the same results.
A SQL query using the IN operator would work, but I've been unable to make
that work.
Any help is appreciated.