WiiMaxx
WiiMaxx

Reputation: 5420

Delete Issue with stored procedure

I wrote a simple stored procedure where I'm not able to find the problem in the code

Stored procedure:

ALTER PROCEDURE dbo.BestellDetail_Delete
        -- Add the parameters for the stored procedure here
    @RefId  AS int

AS

    -- Insert statements for procedure here
    DELETE FROM BestellDetails 
    WHERE       RefBestellId = @RefId

    RETURN

C# Code

SqlCommand cmdBestellDetailsDELETE = new SqlCommand("BestellDetail_Delete", conn);
cmdBestellDetailsDELETE.Parameters.AddWithValue("@RefId", 35);

cmdBestellDetailsDELETE.ExecuteNonQuery();

Error:

Procedure or function 'BestellDetail_Delete' expects parameter '@RefId', which was not supplied.

So could please anyone tell me what I'm doing wrong here?

Upvotes: 0

Views: 65

Answers (1)

Steve
Steve

Reputation: 216263

Missing

  cmdBestellDetailsDELETE.CommandType = CommandType.StoredProcedure;

Without that flag the command type defaults to CommandType.Text and so it is expected to be something like "SELECT....", "DELETE...."

Upvotes: 4

Related Questions