none
Too Many Arguments Error RRS feed

  • Question

  • Hello,

    I am working on a program that uses a product key and login system and a database. I am stuck on a problem because the code is right but visual basic is giving me an error saying "Too Many Arguments".

    Here is the code:

    SQL.AddParam("@item", "%" & TextBox1.Text & "%")
    LoadGrid("SELECT * FROM nwidc_users WHERE product_key LIKE @item;")

    Why is it doing this and how can I fix this error?

    Wednesday, July 18, 2018 6:41 PM

All replies

  • Hello,

    I am working on a program that uses a product key and login system and a database. I am stuck on a problem because the code is right but visual basic is giving me an error saying "Too Many Arguments".

    Here is the code:

    SQL.AddParam("@item", "%" & TextBox1.Text & "%")
    LoadGrid("SELECT * FROM nwidc_users WHERE product_key LIKE @item;")

    Why is it doing this and how can I fix this error?

    What is "LoadGrid", post the code for that...

    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.

    Wednesday, July 18, 2018 9:06 PM
    Moderator
  • Public Sub LoadGrid()
            SQL.ExecQuery("SELECT * FROM nwidc_users;")
            If SQL.HasException(True) Then Exit Sub
    
            dgvData.DataSource = SQL.DBDT
        End Sub

    Here is the code. The dvgData is a datagrid view and the DBDT is a DataTable.
    Wednesday, July 18, 2018 9:09 PM
  • Public Sub LoadGrid()
            SQL.ExecQuery("SELECT * FROM nwidc_users;")
            If SQL.HasException(True) Then Exit Sub
    
            dgvData.DataSource = SQL.DBDT
        End Sub

    Here is the code. The dvgData is a datagrid view and the DBDT is a DataTable.

    See, Your LoadGrid Subroutine does not take any parameters. This is why you are getting the error because you are trying to pass a query to your LoadGrid sub, but your LoadGrid sub does not take any arguments.


    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.

    Wednesday, July 18, 2018 9:18 PM
    Moderator
  • You can modify your LoadGrid sub to take a parameter like this:

        Public Sub LoadGrid(Query As String)
            Sql.ExecQuery(Query)
            If Sql.HasException(True) Then Exit Sub
    
            dgvData.DataSource = Sql.DBDT
        End Sub


    Hire Me For This Job!
    Don't forget to vote for Helpful Posts and Mark Answers!
    *This post does not reflect the opinion of Microsoft, or its employees.

    Wednesday, July 18, 2018 9:23 PM
    Moderator