Vb 2008 "LIKE" not worling as I want it-VBForums
Results 1 to 2 of 2

Thread: Vb 2008 "LIKE" not worling as I want it

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2014
    Posts
    2

    Vb 2008 "LIKE" not worling as I want it

    I'm trying to learn VB 2008 after many years with VB6. I'm using Vb 2008 and not a more recent version as that's what I have. I'm using an Access db
    I'm writing an name & address i/p routine. To be able to quickly select an existing entry, or to avoid duplication I use the LIKE query to select matching names as keystrokes are entered.
    In VB6 this is what I've successfully used for years:-
    mySQL = "SELECT ref,last_name,first_name,post_code,home_phone,addr1,addr2,addr3 FROM addr" & _
    " WHERE last_name LIKE """ & saleaddr(0) & "*"""
    In Vb 2008 I call this routine on keyup:-
    Private Sub showAddr()
    Dim mySQL As String
    Dim i As Integer
    ListBox1.Items.Clear()
    mySQL = "SELECT aLastName FROM address WHERE aLastName LIKE '" & aLastName.Text & "%'"
    da = New OleDb.OleDbDataAdapter(mySQL, con1)
    da.Fill(ds, "Address")
    For i = 0 To ds.Tables("Address").Rows.Count - 1
    ListBox1.Items.Add(ds.Tables("Address").Rows(i).Item("aLastName"))
    ds.Tables("Address").Rows(i).Item("aLastName") = ""
    Next i
    ds.Clear()
    da.Fill(ds, "Address")
    End Sub

    This almost works but it finds duplicates of each applicable entry.
    Could anyone help please?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,942

    Re: Vb 2008 "LIKE" not worling as I want it

    To remove duplicates you must return distinct records, and one way for that is to use the GROUP BY clause.
    Code:
    "SELECT aLastName FROM address WHERE aLastName LIKE '" & aLastName.Text & "%' GROUP BY aLastName"
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.