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.
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)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
command.Connection.Close();
}
}
}
sp
CREATE DEFINER=`root`@`%` PROCEDURE `mysp`(IN sYear VARCHAR(255))
BEGIN
DECLARE 2sYear VARCHAR(255);
SET 2sYear = sYear;
SET @s = CONCAT('SELECT * FROM `mytable_',2sYear,'`;');
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END