Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8711313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:50:46+00:00 2026-06-13T04:50:46+00:00

Good day everyone! I would like to ask for help regarding my code here.

  • 0

Good day everyone! I would like to ask for help regarding my code here. The main concern is to search from the MySQL database the keyword provided by a textbox. Here’s my GUI for reference.

The GUI of my program

When I type my search key on the text box and the selected a column on the combo box, the search query will have its output on the listview. I’ve tried numerous combinations to gain an output, but to no avail.

Here’s my code for you to help me.

Private Sub Search()

    lviClientList.Items.Clear()
    Dim strSqlSearch As String = "SELECT code, Company, StAdd, City, ContactPerson, Phone, Mobile, Email, Remarks FROM tblclients WHERE '@Column' LIKE '%" & txtSearchCriteria.Text & "%'"

    Dim item As New ListViewItem()

    If cboColumns.SelectedIndex = 0 Then
        column = "code"
    ElseIf cboColumns.SelectedIndex = 1 Then
        column = "Company"
    ElseIf cboColumns.SelectedIndex = 2 Then
        column = "StAdd"
    ElseIf cboColumns.SelectedIndex = 3 Then
        column = "City"
    ElseIf cboColumns.SelectedIndex = 4 Then
        column = "ContactPerson"
    ElseIf cboColumns.SelectedIndex = 5 Then
        column = "Phone"
    ElseIf cboColumns.SelectedIndex = 6 Then
        column = "Mobile"
    ElseIf cboColumns.SelectedIndex = 7 Then
        column = "Email"
    ElseIf cboColumns.SelectedIndex = 8 Then
        column = "Remarks"
    End If

    Dim mysqlCommand As New MySqlCommand(strSqlSearch, mysqlConnection)
    mysqlCommand.Parameters.AddWithValue("@Column", column)

    Try
        mysqlConnection.Open()
        mysqlReader = mysqlCommand.ExecuteReader()

        Do While mysqlReader.Read()

            item = lviClientList.Items.Add(mysqlReader("code").ToString)
            item.SubItems.Add(mysqlReader("Company").ToString)
            item.SubItems.Add(mysqlReader("StAdd").ToString)
            item.SubItems.Add(mysqlReader("City").ToString)
            item.SubItems.Add(mysqlReader("ContactPerson").ToString)
            item.SubItems.Add(mysqlReader("Phone").ToString)
            item.SubItems.Add(mysqlReader("Mobile").ToString)
            item.SubItems.Add(mysqlReader("Email").ToString)
            item.SubItems.Add(mysqlReader("Remarks").ToString)

        Loop

    Catch ex As Exception

        MsgBox("No results found.", MsgBoxStyle.OkOnly, "Project Analysis System")

    Finally

        mysqlReader.Close()
        mysqlConnection.Close()

    End Try

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:50:47+00:00Added an answer on June 13, 2026 at 4:50 am

    It is not clear why your code doesn’t work well. Try to change the code in your Catch clause

    MsgBox("No results found.", MsgBoxStyle.OkOnly, "Project Analysis System")
    

    into

    Msgbox(ex.Message.ToString(), MsgBoxStyle.OkOnly, "Project Analysis System")
    

    so you will know what the exact error is.

    You can concatenate the value for the ColumnName since it is statically set in your code. But the value on WHERE should be parameterized as it is the one entered by the user.

    Try this modified Code,

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day everyone. I would like to ask for help regarding my code to
Good day! My regular expression is really bad and I would like to ask
Good day everyone! I would just want to ask what is wrong with what
Good day, everyone! I have here a program that sorts 50,000 words from a
Good day everyone! I have a problem regarding my date. It needs to be
Good day everyone, so here, I have a problem with my repeater control's SQL
Good day everyone, i have faced with such an issue as linkage error like
Good Day Everyone I was hoping if you could help me understand the concepts
Good day, everyone. Could somebody explain why following code does work in Google Chrome
Good day everyone, I'm an independent game developer who has, in the past, primarily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.