It is not clear why your code does not work. Try changing the code in the sentence.Catch
MsgBox("No results found.", MsgBoxStyle.OkOnly, "Project Analysis System")
at
Msgbox(ex.Message.ToString(), MsgBoxStyle.OkOnly, "Project Analysis System")
so that you know what the exact mistake is.
ColumnName, . WHERE , .
,
Private Sub Search()
lviClientList.Items.Clear()
Dim item As New ListViewItem()
Dim _isFound As Boolean = False
Dim colName() As String = {"code", "Company", "StAdd", "City", "ContactPerson", "Phone", "Mobile", "Email", "Remarks"}
Dim strSqlSearch As String = "SELECT code, Company, StAdd, City, " & _
"ContactPerson, Phone, Mobile, Email, Remarks " & _
"FROM tblclients " & _
"WHERE " & colName(cboColumns.SelectedIndex) & " LIKE CONCAT('%', @valueName, '%')"
Using myConn As New MySqlConnection("connectionStringHere")
Using myComm As New MySqlCommand()
With myComm
.Connection = myConn
.CommandType = CommandType.Text
.CommandText = strSqlSearch
.Parameters.AddWithValue("@valueName", txtSearchCriteria.Text);
End With
Try
myConn.Open()
Dim myReader As MySqlDataReader = myComm.ExecuteReader()
While myReader.Read()
_isFound = True
item = lviClientList.Items.Add(myReader("code").ToString)
item.SubItems.Add(myReader("Company").ToString)
item.SubItems.Add(myReader("StAdd").ToString)
item.SubItems.Add(myReader("City").ToString)
item.SubItems.Add(myReader("ContactPerson").ToString)
item.SubItems.Add(myReader("Phone").ToString)
item.SubItems.Add(myReader("Mobile").ToString)
item.SubItems.Add(myReader("Email").ToString)
item.SubItems.Add(myReader("Remarks").ToString)
End While
If Not _isFound Then
MsgBox("No results found.", MsgBoxStyle.OkOnly, "Project Analysis System")
End If
Catch ex As MySqlException
Msgbox(ex.Message.ToString(), MsgBoxStyle.OkOnly, "Project Analysis System")
End Try
End Using
End Using
End Sub