mysql adding parameters in asp.net vb
-
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
-
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
Hi there. Do you need to issue the
.Prepare()
method after setting up yourCommand
? -
Hi there. Do you need to issue the
.Prepare()
method after setting up yourCommand
? -
.Prepare method? Out of all the searches Ive done on google ive not seen this mentioned before? could you expand on this? Thanks.
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.
-
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.