Results 1 to 4 of 4

Thread: how can i select from table using many string values from text box?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    how can i select from table using many string values from text box?

    how can i select from table using many string values from text box?
    create table mytable( country varchar(30), city varchar(30))
    insert into mytable values('Ethiopia','Addis Ababa')
    insert into mytable values('Kenya','Nairobi')
    insert into mytable values('France','Paris')
    insert into mytable values('Japan','Tokyo')
    then i have a text box that receives countries.
    when i try to enter Ethiopia kenya,
    i will expect to get Addis Ababa Kenya,
    if i enter France Japan Ethiopia,
    i will expect to get Paris Tokyo Addis Ababa
    I think all this has done using split if i am not wrong.
    so could you show me how can i select such conditions?
    note that the value of textbox is more than one countries,
    but i know when the value of textbox is one country only.
    dim str as string
    str="select city from mytable where country=' "&textbox1.text&" '"

    my problem when i try to enter two or more countries name at same time.
    sorry for posting again!
    your help is crucial 4 me!
    thanks

  2. #2
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    Re: how can i select from table using many string values from text box?

    See the other post. Please flag the wrong posts (and I'm not sure but the owner of the thread can delete it as well).

  3. #3
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: how can i select from table using many string values from text box?

    Below is code that should do this - but beware, it will need tweaking to be more resiliant to user input - however, it should give you a basis.

    Code:
            Dim searchString As String
            searchString = "'" & Replace(TextBox1.Text, " ", "','") & "'"
    
            Dim sql As String
            sql = "SELECT city FROM mytable WHERE country IN (" & searchString & ")"
    Martin J Wallace (Slaine)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Re: how can i select from table using many string values from text box?

    Hello Slaine!
    Thanks your answer works fine!

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