Hello there,
I am trying to run a mysql stored procedure using c# asp net.
This stored procedure tried in mysql works fine.
Instead tested on code behind of my project I have mysql syntax error.
> ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-8.0.12]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 'mysp' at line 1
How to extract the output of "PRINT" Command i.e the procedure in C# how can i do that ?
.cs
using (OdbcConnection cn =new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{using (OdbcCommand command =new OdbcCommand("mysp", cn))
{try
{
command.Connection.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("sYear", ddlyear.SelectedValue);using (OdbcDataAdapter sda = new OdbcDataAdapter(command))
{
DataTable dt = new DataTable();
sda.Fill(dt);
gv.DataSource = dt;
gv.DataBind();
}
}
catch (Exception ex)
{thrownew ApplicationException("operation failed!", ex);
}finally
{
command.Connection.Close();
}
}
}
sp
CREATE DEFINER=`root`@`%`PROCEDURE`mysp`(IN sYear VARCHAR(255))BEGINDECLARE2sYear VARCHAR(255);SET2sYear = sYear;SET @s = CONCAT('SELECT * FROM `mytable_',2sYear,'`;');PREPARE stmt FROM @s;EXECUTE stmt;DEALLOCATEPREPARE stmt;END