Search code examples
sqlvb.netdatasetsql-like

SQL Like statement not working in Visual Basic


Dim strText As String = tbRefine.Text
Dim sql As String = "SELECT user_name,forename,surname,game_cash,reg_group FROM tblGame WHERE user_name LIKE '" + strSearchText + "' & '*'"
Dim dsRefine As New DataSet
GetDataset(sql, "tblGame", dsRefine)

MsgBox(dsRefine.Tables("tblGame").Rows(0).Item(2).ToString)

This is not working, it crashes and says there is nothing in the dataset. I know the dataset function works as its worked successfully before. When i print out the sql statement into microsoft access it works fine. What am i doing wrong


Solution

  • Try this:

    "SELECT user_name,forename,surname,game_cash,reg_group
     FROM tblGame
     WHERE user_name LIKE '%" + strSearchText + "%'"