sp_executesql - Procedure or function expects parameter which was not supplied

后端 未结 3 1844
后悔当初
后悔当初 2021-01-18 13:17

I am working with Entity Framework in C# and am having an issue which I have tracked down to the SQL statement being generated.

The stored procedure takes in a table

3条回答
  •  鱼传尺愫
    2021-01-18 14:11

    I had the same exact issue.

    Once you declare the command, you have to specify the command type

    SqlCommand cmd = new SqlCommand(@"sp_name", con);
    
    cmd.CommandType = CommandType.StoredProcedure;
    

    If you don't do this, .NET will generate a command for using sp_executesql... and that is the problem is ... you specify the command type as above and the code generated is using

    execute storedprocedure @param1 = ...
    

提交回复
热议问题