-
Feb 21st, 2012, 03:59 PM
#1
Thread Starter
New Member
Seach dataset from multi-value textbox
Greetings all,
I am attempting to provide a windows application to a co-worker that takes X number of employee IDs, seperated by commas, in a single text box and looks them up in a SQL dataset. I've set my data set up and have added a text box, a button and gridview to my form. How can I configure the code to allow searching multiple values sepearated by commas in a single textbox?
Ex textbox) 23,64,76,23443,55552,12,23123213
I would like a gridview to show all columns from the dataset for any row matching any of the values in the textbox.
Thanks,
Kevin
-
Feb 21st, 2012, 04:45 PM
#2
Thread Starter
New Member
Re: Seach dataset from multi-value textbox
Would really appreciate some help on this. The only solution I have in place right now will only search for one employee ID at a time using a new query like
SELECT EmployeeID, BusinessUnit, ManagerSSO, ManagerName, geJobFunction, title, FullName
FROM ldap_csv
WHERE (EmployeeID LIKE @TextBox1 + N'%')
and this is not exactly what I am looking for.
Thanks
-
Feb 21st, 2012, 04:56 PM
#3
Thread Starter
New Member
Re: Seach dataset from multi-value textbox
The code for searching from a text box one employee ID at a time after a buttonclick
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Me.Ldap_csvTableAdapter.FillBySearchSSO(Me.ITAM_exportsDataSet.ldap_csv, TextBox1.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
Again, I want to be able to search for multiple Employee IDs in one text box seperated by commas.
Thanks
-
Feb 21st, 2012, 05:47 PM
#4
Re: Seach dataset from multi-value textbox
A select statement with a bunch of ors within the where clause should do it.
Select * from myTable where MyField=value1 or myfield=value2.... and so on
You could use split() to break the data in the textbox down to an array based on the comma seperator then use a loop to build the string of or statements for yoru where clause based on how many items were actually in the text box.
-
Feb 22nd, 2012, 08:30 AM
#5
Thread Starter
New Member
Re: Seach dataset from multi-value textbox
Thanks for the reply! I thought of that exact solution but am unsure of how to implement it. I have a split string in place as detailed below that sepeates a string of comma delimited values:
Code:
Dim s As String = TextBox1.Text
Dim words As String() = s.Split(New Char() {","c})
Dim word As String
How could I now run how ever many values a user enters through a loop to search for each of them?
-
Feb 22nd, 2012, 09:42 AM
#6
Re: Seach dataset from multi-value textbox
Something like this will build a where clause with all the values that you can then use in your SQL Select statement.
Code:
Dim MyArray() As String = TextBox1.Text.Split(",")
Dim WhereClause As String = ""
For X As Integer = 0 To MyArray.Length - 1
If X = 0 Then
WhereClause = " Where MyField='" & MyArray(0) & "'"
Else
WhereClause += " or MyField='" & MyArray(X) & "'"
End If
Next
MsgBox(WhereClause)
If your field is numeric you would drop the 's
-
Feb 22nd, 2012, 10:02 AM
#7
Thread Starter
New Member
Re: Seach dataset from multi-value textbox
Thanks for your help - I've got it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|