Search code examples
mysqlvb.netsoundex

Mysql Soundex in VB.NET format


I have these lines of codes and Im trying to look into my database for soundex results but apparently it's not returning any result.

con.Open()

    Try
        Dim query As String
        query = "SELECT * FROM table_name WHERE column_name LIKE CONCAT('" & "%" & "',SOUNDEX('" & input & "'),'" & "%" & "')"
        cmd = New MySqlCommand(query, con)
        adapter.SelectCommand = cmd
        reader = cmd.ExecuteReader
        Dim list As New ListViewItem
        While reader.Read()
            list = ListView1.Items.Add(dr(1).ToString())
            list.SubItems.Add(dr(2).ToString())
        End While
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

    con.Close()

It doesn't even throw exception on MessageBox.

To ensure there is data returned from my database before i did the query above, i did select * from table_name.

Thanks!


Solution

  • I'll prefix this by saying that I am not at all familiar with MySQL, but the Soundex algorithm typically returns a "code" that will be the same for similar sounding words. e.g.

    SOUNDEX('Smith') = 'S530'
    SOUNDEX('Smythe') = 'S530'
    

    So, in order to find records where the column_name value sounds like the input value you would want something like this (heed the warnings about SQL injection issues and don't use string concatenation as shown below!):

    query = "SELECT * FROM table_name WHERE SOUNDEX(column_name) = SOUNDEX('" & input & "')"