C # Stored procedure or function expects parameter which is not supplied

3

I get the error

  

'sp_InsertaLandingPageTest' expects parameter '@IDUSUARIO', which   was not supplied, l id

is supposed to be generated from the maximum but I really have no idea how to do it if you insert data into the stored procedure if you can.

This is my stored procedure

ALTER PROCEDURE [VIANNEY].[sp_InsertaLandingPagePrueba]                                 
(
 @USUARIOCREACION   NVARCHAR(250),                          
 @USUARIOMODIFICACION   NVARCHAR(250),                          
 @IDUSUARIO INTEGER,                            
 @NOMBRE_IMG NVARCHAR(250),                         
 @URL_IMGN VARCHAR(200),
 @URL_HREF VARCHAR(200)
)                   
AS                                  
--Declare                               
    --@v_EMAIL nvarchar
BEGIN                                   
SET NOCOUNT ON;                                     
IF NOT EXISTS(SELECT * FROM VIANNEY.LANDING_PAGE_PRUEBA WITH (NOLOCK) where idusuario = @IDUSUARIO)                             
Begin                               
    insert into vianney.LANDING_PAGE_PRUEBA                         
        (fechaCreacion,UsuarioCreacion,FechaModificacion,UsuarioModificacion,                       
        IdUsuario,Url_Img, Url_Href, Nombre_Image, Num_Id_Dashboard)                        
    Values                          
        (getdate(),@USUARIOCREACION,getdate(),@USUARIOMODIFICACION,
        (SELECT ISNULL((MAX(IdUsuario)+1),1) FROM VIANNEY.LANDING_PAGE_PRUEBA),                     
        @URL_IMGN, @URL_HREF, @NOMBRE_IMG,
        (SELECT ISNULL((MAX(Num_Id_Dashboard)+1),1) FROM VIANNEY.LANDING_PAGE_PRUEBA)
        );                      
end                             

SELECT @@ROWCOUNT as afectadas                              
END 

and this is my method where I want to insert data from a web form

public Boolean AgregarRegistro_LandingPage(string UsuarioC, string UsuarioM, string nombreBanner, string Url_Image, string Url_Href)
    {
        //string msj = " ";
        bool correcto = false;

            SqlCommand cmd = new SqlCommand("VIANNEY.sp_InsertaLandingPagePrueba", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            con.Open();
            cmd.Parameters.AddWithValue("@USUARIOCREACION", UsuarioC);
            cmd.Parameters.AddWithValue("@USUARIOMODIFICACION", UsuarioM);
            cmd.Parameters.AddWithValue("@NOMBRE_IMG", nombreBanner);
            cmd.Parameters.AddWithValue("@URL_IMGN", Url_Image);
            cmd.Parameters.AddWithValue("@URL_HREF", Url_Href);

            if (Convert.ToInt32(cmd.ExecuteScalar()) != 0)
            {
                correcto = true;
                //msj = "Banner agregado correctamente";
            }

            con.Close();

            return (correcto);

    }

If you could help me, I would appreciate it too.

    
asked by Amairani Fernanda 24.04.2017 в 19:31
source

1 answer

1

The error is quite clear, you are not sending @IDUSUARIO when calling the procedure from the code.

Try the following: declare that parameter so that it receives a default value:

ALTER PROCEDURE [VIANNEY].[sp_InsertaLandingPagePrueba]                                 
(
 @USUARIOCREACION       NVARCHAR(250),
 @USUARIOMODIFICACION   NVARCHAR(250),
 @IDUSUARIO             INTEGER = 0,    -- Valor por default
 @NOMBRE_IMG            NVARCHAR(250),
 @URL_IMGN              VARCHAR(200),
 @URL_HREF              VARCHAR(200)
)

and that error will not mark you. How you do it to give it the correct value in where idusuario = @IDUSUARIO) is another issue.

    
answered by 24.04.2017 / 20:01
source