none
Issue with ODBC MySql Query in Visual Basic RRS feed

  • Question

  • Hi,

    We have a program in VB.net with MSAccess as database.

    We migrated out database to MySQL and now facing issue with Queries that was written for MSAccess.

    Below was the query Written for Msaccess.

            selectComputerStatement = "SELECT * FROM tbl_asset WHERE asset_name = @asset_name;"
            Using cn As New OdbcConnection(ConnectionString)
                Using cmdComputer As New OdbcCommand With {.Connection = cn}
                    cmdComputer.Parameters.AddWithValue("@asset_name", asset_name)
                    cmdComputer.CommandText = selectComputerStatement
                    Try
                        cn.Open()
                        Dim readerComputer = cmdComputer.ExecuteReader()
                        If readerComputer.HasRows() Then

    Tried this query from MySQL server and it returns results so this must be issue with the Code itself. Please Help


    Coderv9

    Wednesday, March 20, 2019 3:40 PM

All replies

  • What specifically is the issue?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, March 20, 2019 4:06 PM
    Moderator
  • Ok, so what exception are you getting?

    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    Wednesday, March 20, 2019 4:06 PM
  • There are no exception. The query Returns entire rows from DB instead of single maching row :(

    Coderv9

    Thursday, March 21, 2019 8:42 AM
  • There are no exception. The query Returns entire rows from DB instead of single maching row :(

    Coderv9

    To diagnose things, comment out the following line

    cmdComputer.Parameters.AddWithValue("@asset_name", asset_name)

    Then change the SELECT statement to

    selectComputerStatement = "SELECT * FROM tbl_asset WHERE asset_name = 'WIN-NTNM01';"

    What is the result when running the modified version?

    If not correct try this version

    selectComputerStatement = "SELECT * FROM tbl_asset WHERE asset_name = 'WIN-NTNM01' limit 1;"



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, March 21, 2019 11:45 AM
    Moderator