Stack Exchange
Error en procedimiento almacenado MySql?
Estoy ejecutando un SELECT en un procedimiento almacenado en una columna VARCHAR(50) lo ejecuto desde mi codigo C# y me devuelve un error que dice "No Support the Same Name"...lo extraño es que si la misma consulta la paso como una string desde mi codigo no me devuelve error;
Sp MySql :
    CREATE DEFINER=`Admin`@`%` PROCEDURE `Sp_GetInfoContractNumber`( IN contractNumber VARCHAR(50))
    BEGIN
        SELECT A.IdContract, A.IdClient, A.IdClientType ,A.IdContractType ,A.ContractDate ,A.TermDate,A.ContractNumber ,A.Legal_Description ,A.DocumentFile, B.IdAnnex ,B.Name AS NameAnnex , B.BasicRate , B.IdPricingModelBase ,
                C.RFC ,C.SocialReason ,C.Mail ,D.IdClientGroup , D.NAme AS NameClientGroup ,D.IdAccountGig , D.Description AS DescriptionClientGroup,E.IdRegionalClient ,E.Description AS DescriptionRegionalClient,
                B.ActivateDate,B.StartDate,B.EndDate,B.IdStatusAnnex,
                (SELECT NAME FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS NamePlan,
                (SELECT PriceMin FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMin,
                (SELECT PriceMax FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMax,
                (SELECT PriceMonthCU FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMonthCU,
                (SELECT PriceMonthSU FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMonthSU
                FROM Contracts A, Annexs B, Client C, ClientGroup D, RegionalClient E  WHERE 
                A.ContractNumber = contractNumber
                AND A.IdClient = B.IdClient
                AND A.IdContract = B.IdContract 
                AND C.IdClient = A.IdClient
                AND E.Client = A.IdClient 
                AND C.IdClientGroup = D.IdClientGroup;           
END

Codigo C#:
public List<InfoDataAdmClient> ListadoContractNumberSp(string SpName, string contractNumber )
{
    List<InfoDataAdmClient> InfoDataAdmClient = new List<InfoDataAdmClient>();
    DataTable dataTabla = new DataTable();
    MySqlConnection Conexion = new MySqlConnection(StringConexion);
    using (Conexion)
    {
        Conexion.Open();
        MySqlCommand command = new MySqlCommand(SpName, Conexion);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Clear();
        new MySqlParameter("@contractNumber",contractNumber);
        MySqlDataAdapter dataAdaptador = new MySqlDataAdapter(command);
        dataAdaptador.Fill(dataTabla); ***//AQUI EL ERROR***
        Conexion.Close();
    }
    EngineApi Funcion = new EngineApi();
    InfoDataAdmClient = Funcion.ConvertirToListInfoDataAdmClient(dataTabla);
    return InfoDataAdmClient;
}

Imagen del error:

Si lo hago de esta forma si me lo hace bien ...
public List<InfoDataAdmClient> InfoDataAdmClientNumber(string  contractNumber)
{
    List<InfoDataAdmClient> infoDataAdmClient = new List<InfoDataAdmClient>();
    EngineDb Metodo = new EngineDb();
    // infoDataAdmClient = Metodo.ListadoContractNumberSp("Sp_GetInfoContractNumber", contractNumber);
    string SQL= "SELECT  A.IdContract,A.IdClient ,A.IdClientType ,A.IdContractType ,A.ContractDate ,A.TermDate,A.ContractNumber ,A.Legal_Description ,A.DocumentFile, B.IdAnnex ,B.Name AS NameAnnex , B.BasicRate , B.IdPricingModelBase ," +
    " C.RFC ,C.SocialReason ,C.Mail ,D.IdClientGroup , D.NAme AS NameClientGroup ,D.IdAccountGig , D.Description AS DescriptionClientGroup,E.IdRegionalClient ,E.Description AS DescriptionRegionalClient," +
    " B.ActivateDate,B.StartDate,B.EndDate,B.IdStatusAnnex," +
    " (SELECT NAME FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS NamePlan," +
    " (SELECT PriceMin FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMin," +
    " (SELECT PriceMax FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMax," +
    " (SELECT PriceMonthCU FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMonthCU," +
    " (SELECT PriceMonthSU FROM PricingModelBase WHERE IdPricingModel = B.IdPricingModelBase) AS PriceMonthSU " +
    " FROM Contracts A, Annexs B, Client C, ClientGroup D, RegionalClient E  WHERE " +
    " A.ContractNumber =" + "'" + contractNumber + "'"  + " AND A.IdClient = B.IdClient AND A.IdContract = B.IdContract AND C.IdClient = A.IdClient AND E.Client = A.IdClient AND C.IdClientGroup = D.IdClientGroup";
    infoDataAdmClient = Metodo.ListadoContractNumber(SQL, contractNumber);
    return infoDataAdmClient;
}


Lo que sucede es que nunca asignas el parametro, solo haces el new pero lo dejas en e aire sin asignar a la coleccion Parameters
public List<InfoDataAdmClient> ListadoContractNumberSp(string contractNumber)
{
    List<InfoDataAdmClient> InfoDataAdmClient = new List<InfoDataAdmClient>();
    DataTable dataTabla = new DataTable();

    using (MySqlConnection Conexion = new MySqlConnection(StringConexion))
    {
        MySqlCommand command = new MySqlCommand("Sp_GetInfoContractNumber", Conexion);
        command.CommandType = CommandType.StoredProcedure;

        var contractParam = new MySqlParameter("?contractNumber",contractNumber);
        command.Parameters.Add(contractParam);

        MySqlDataAdapter dataAdaptador = new MySqlDataAdapter(command);
        dataAdaptador.Fill(dataTabla);
    }

    EngineApi Funcion = new EngineApi();
    InfoDataAdmClient = Funcion.ConvertirToListInfoDataAdmClient(dataTabla);

    return InfoDataAdmClient;
}

Te estan faltando estas lineas
var contractParam = new MySqlParameter("?contractNumber",contractNumber);
command.Parameters.Add(contractParam);

donde asignas el parametro al command
Nota: prueba si el nombre del parametro no debe ir con ? en lugar de @ ya que este se suele usar para sql server

Hola ...Leandro ... Agregue la linea que me sugieres ..Igual me sigue devolviendo el mismo error

pero intentaste definir el parametro con el ? o quizas dejarle el @ no recuerdo si estos eran necesario seria cuestion de probar https://dev.mysql.com/doc/connector-net/en/connector-net-programming-stored-using.html

pude solucionar modificando mi codigo c# desde donde invoco el Sp
   public List<InfoDataAdmClient> ListadoContractNumberSp(string SpName, string contractNumber )
        {
            List<InfoDataAdmClient> InfoDataAdmClient = new List<InfoDataAdmClient>();
            DataTable dataTabla = new DataTable();
            MySqlConnection Conexion = new MySqlConnection(StringConexion);
            using (Conexion)
            {
                Conexion.Open();
                MySqlCommand command = new MySqlCommand(SpName, Conexion);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@contractNumber",contractNumber);
                command.Parameters["@contractNumber"].Direction = ParameterDirection.Input;
                MySqlDataAdapter dataAdaptador = new MySqlDataAdapter(command);
                dataAdaptador.Fill(dataTabla);
                Conexion.Close();
            }
            EngineApi Funcion = new EngineApi();
            InfoDataAdmClient = Funcion.ConvertirToListInfoDataAdmClient(dataTabla);
            return InfoDataAdmClient;
        }

