Results 1 to 7 of 7

Thread: Seach dataset from multi-value textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    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

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    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

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    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?

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    5

    Resolved 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
  •  



Click Here to Expand Forum to Full Width