Procedure or function expects parameter which was not supplied

15,684

Change the command type to Procedure

Share:
15,684
eftpotrm
Author by

eftpotrm

Updated on June 15, 2022

Comments

  • eftpotrm
    eftpotrm almost 2 years

    Driving me mad on a personal project; I know I've done this before but elsewhere and don't have the code. As far as I can see, I'm setting the parameter, I'm setting its value, the connection is open, yet when I try to fill the dataset I get the error 'Procedure or function expects parameter "@test" which was not supplied'.

    (This is obviously a simplified test! Same error on this or the real, rather longer code though.)

    C#:

    SqlCommand l_oCmd;
    DataSet l_oPage = new DataSet();
    
    l_oCmd = new SqlCommand("usp_test", g_oConn);
    l_oCmd.Parameters.Add(new SqlParameter("@test", SqlDbType.NVarChar));
    l_oCmd.Parameters[0].Value = "hello world";
    
    SqlDataAdapter da = new SqlDataAdapter(l_oCmd);
    da.Fill(l_oPage);
    

    SQL:

    create procedure usp_test
    (
        @test nvarchar(1000)
    )
    as
    select @test
    

    What have I missed?

  • Gordon Bell
    Gordon Bell over 12 years
    Ugh, should have caught that. That was driving me crazy.
  • davewilliams459
    davewilliams459 almost 12 years
    Long time no ADO.Net. (That's my excuse, I'm sticking with it)
  • Michael Earls
    Michael Earls almost 8 years
    I had this exact same issue. That's what I get for spending so much time with Entity Framework. I forgot my roots...