I'm developing a reporting web with Visual Studio 2017. All my MYSQL queries are parameterized and works properly. The problem is in some queries that have EXECUTE command.
For example:
Instead of
SELECT * FROM tabla WHERE id=@id
I've put
set @sentencia='SELECT * FROM tabla WHERE id=@id'
PREPARE stmt FROM @sentencia;
EXECUTE stmt using @id;
DEALLOCATE PREPARE stmt;
The execute case doesn't break but doesn't work because return no data.
I've tried this:
set @sentencia='SELECT * FROM tabla WHERE id=?'
PREPARE stmt FROM @sentencia;
EXECUTE stmt using @id;
DEALLOCATE PREPARE stmt;
But It doesn't work. The error message is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '16; DEALLOCATE PREPARE stmt' at line 1
16 corresponds to the value I've given to the parameter @id in my code.
Dim myConnectionMYSQL As New MySql.Data.MySqlClient.MySqlConnection
myConnectionMYSQL.ConnectionString = CadenaDeConexion()
myConnectionMYSQL.Open()
Dim myCommandMYSQL As New MySql.Data.MySqlClient.MySqlCommand(_Sentencia, myConnectionMYSQL)
myCommandMYSQL.CommandTimeout = 9000
myCommandMYSQL.Parameters.Add("@id", SqlDbType.Int, 100)
myCommandMYSQL.Parameters("@id").Value = 16
Dim daMYSQL As New MySql.Data.MySqlClient.MySqlDataAdapter(myCommandMYSQL)
Dim dtMYSql As New DataTable
daMYSQL.Fill(dtMYSql)
Anyone knows a possible solution? Thanks a lot!