Click here to Skip to main content
15,886,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SELECT * FROM [M_Details] where Dcat IN (@Cats) if I give like this in dataset table adapter in vb.net 2010, multiple input values are not filtering. Suppose I pass one argument and then it's working. But if I pass by an argument with more than one value, then it's not working.

What I have tried:

SELECT * FROM [M_Details] where Dcat IN ('Home','Shop')
This direct code with values is working. But I need to pass by user input category values. Please Help me. Thanks in advance.
Posted
Updated 22-Oct-22 7:03am
v2

I'd suggest to read this excellent tip: Using comma separated value parameter strings in SQL IN clauses[^]
 
Share this answer
 
I found this solution for multiple word search to a same column in code.
Paste this code as Function. and call in to textbox control for required inputs.

Private Sub TextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox.TextChanged

'multi words search inputs
Me.DataGridView.DataSource = colMultiSearch(TextBox.Text, "yourColumn")

End Sub


Private Function colMultiSearch(ByVal strFindwords As String, ByVal strColumnName As String) As DataTable

Dim selitems() As String
Erase selitems

'multi input words will be converts into array and separted with comma.
selitems = Split(strFindwords, ",")

'check database connection if success from database module
If OpenDB() = True Then

Using cmd As SQLiteCommand = New SQLiteCommand

Dim paraName As String
Dim indx As Integer = 0

'if blank input then show all data of input column
If strFindwords = "" Then

Dim mySearchQuery1 As String = "SELECT * FROM yourtable WHERE trim(" & strColumnName & ") LIKE '%'"

'show all data query
cmd.CommandText = (mySearchQuery1)

Else
'multiple word search query
Dim mySearchQuery As New StringBuilder("Select * from yourtable")
'column name input here
mySearchQuery.Append(" WHERE trim(" & strColumnName & ") IN (")

For Each myWord As String In selitems

'define column parameter input here
'multi parameters will be adding here automatically by number of word search
paraName = "@column" & indx

'multi parameters will be separted by comma
If indx > 0 Then mySearchQuery.Append(", ")

mySearchQuery.Append(paraName)

cmd.Parameters.AddWithValue(paraName, Trim(myWord))
'Console.WriteLine(CatChk)

'parameter input count
indx += 1
Next
mySearchQuery.Append(")")

'multiple word search output
cmd.CommandText = (mySearchQuery.ToString)
End If

cmd.Connection = Conn

'final data evaluation
Using sda As SQLiteDataAdapter = New SQLiteDataAdapter(cmd)
Dim dt As DataTable = New DataTable
sda.Fill(dt)
Return dt
End Using

End Using
End If

End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900