Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. mysql adding parameters in asp.net vb

mysql adding parameters in asp.net vb

Scheduled Pinned Locked Moved Database
helpcsharpasp-netdatabasemysql
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jetset32
    wrote on last edited by
    #1

    hi all, I wonder if anyone can help with this one, alls im trying to do is add a parameter to a query, i have tried for days but cannot get this to work!! heres my code; myConnection = New MySqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) strSQL = "SELECT SubCatID,CategoryID,SubCatName,Multibuy,SubCatPic FROM SubCategory WHERE CategoryID = ?CategoryID AND Multibuy='Single' ORDER BY SubCatName, SubCatID;" Command = New MySqlCommand(strSQL, myConnection) myDataAdapter = New MySqlDataAdapter(strSQL, myConnection) Command.Parameters.Add("?CategoryID", 1) Command.Parameters("?CategoryID").Direction = ParameterDirection.Input I get the error ; Parameter '?CategoryID' must be defined i have tried everyway i think possible, PLEASE i hope someone can help or point me in the right direction! Thanks. Jetset

    M 1 Reply Last reply
    0
    • J jetset32

      hi all, I wonder if anyone can help with this one, alls im trying to do is add a parameter to a query, i have tried for days but cannot get this to work!! heres my code; myConnection = New MySqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) strSQL = "SELECT SubCatID,CategoryID,SubCatName,Multibuy,SubCatPic FROM SubCategory WHERE CategoryID = ?CategoryID AND Multibuy='Single' ORDER BY SubCatName, SubCatID;" Command = New MySqlCommand(strSQL, myConnection) myDataAdapter = New MySqlDataAdapter(strSQL, myConnection) Command.Parameters.Add("?CategoryID", 1) Command.Parameters("?CategoryID").Direction = ParameterDirection.Input I get the error ; Parameter '?CategoryID' must be defined i have tried everyway i think possible, PLEASE i hope someone can help or point me in the right direction! Thanks. Jetset

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. Do you need to issue the .Prepare() method after setting up your Command?

      J 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. Do you need to issue the .Prepare() method after setting up your Command?

        J Offline
        J Offline
        jetset32
        wrote on last edited by
        #3

        .Prepare method? Out of all the searches Ive done on google ive not seen this mentioned before? could you expand on this? Thanks.

        M 1 Reply Last reply
        0
        • J jetset32

          .Prepare method? Out of all the searches Ive done on google ive not seen this mentioned before? could you expand on this? Thanks.

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          Hi there. I may have offered that too soon - I saw it used in some MySql .NET Connector examples and thought it may be something to look at. As I look at the .chm documentation, it indicates that the method is not yet supported (?) But then there is a different section that describes the following: 4.3.2. Preparing Statements in MySQL Connector/NET To prepare a statement, create a command object and set the .CommandText property to your query. After entering your statement, call the .Prepare method of the MySqlCommand object. After the statement is prepared, add parameters for each of the dynamic elements in the query. After you enter your query and enter parameters, execute the statement using the .ExecuteNonQuery(), .ExecuteScalar(), or .ExecuteReader methods. For subsequent executions, you need only modify the values of the parameters and call the execute method again, there is no need to set the .CommandText property or redefine the parameters. So now I'm not sure which is right.

          J 1 Reply Last reply
          0
          • M Mike Ellison

            Hi there. I may have offered that too soon - I saw it used in some MySql .NET Connector examples and thought it may be something to look at. As I look at the .chm documentation, it indicates that the method is not yet supported (?) But then there is a different section that describes the following: 4.3.2. Preparing Statements in MySQL Connector/NET To prepare a statement, create a command object and set the .CommandText property to your query. After entering your statement, call the .Prepare method of the MySqlCommand object. After the statement is prepared, add parameters for each of the dynamic elements in the query. After you enter your query and enter parameters, execute the statement using the .ExecuteNonQuery(), .ExecuteScalar(), or .ExecuteReader methods. For subsequent executions, you need only modify the values of the parameters and call the execute method again, there is no need to set the .CommandText property or redefine the parameters. So now I'm not sure which is right.

            J Offline
            J Offline
            jetset32
            wrote on last edited by
            #5

            Mike, Thanks alot, you have helped me out loads with that, my parameter code was correct but becuase I wasnt using the execute read method it wasnt working! It is now! Thanks alot Jet set:laugh:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups