Skip to content
Advertisement

passing parameters to a stored procedure in C#

How can i send three parameters a to stored procedure in sql?

Here is my error: Procedure or function GetIslemIdleri has too many arguments specified.

This is my stored procedure:

CREATE PROCEDURE GetIslemDetayIdleri 

@islemId int,
@dovizTanim nvarchar(10),
@yapilanIslemTuru nvarchar(20)
AS
BEGIN
    SET NOCOUNT ON;

SELECT ([t0].[TOPLAMTUTAR]) + ([t0].[KDVTUTAR]) AS [value]
FROM [dbo].[TBLP1ISLEMDETAY] AS [t0]
INNER JOIN [dbo].[TBLP1ISLEM] AS [t1] ON [t1].[ID] = [t0].[ISLEM_ID]
WHERE ([t0].[ISLEM_ID] = @islemId) AND 
      ([t0].[FIYATBIRIM] = @dovizTanim) AND 
      ([t1].[YAPILANISLEM] = @yapilanIslemTuru) AND 
      ([t0].[KDVDAHILMI] = 0)
END

Here is my code:

        decimal kurToplamQuery = 0;
        string connString = System.Configuration.ConfigurationManager.ConnectionStrings["LocalSqlServer1"].ConnectionString;

        SqlConnection sqlConn = new SqlConnection(connString);
        sqlConn.Open();

        SqlCommand cmd;

        cmd = new SqlCommand("GetIslemIdleri", sqlConn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@islemId", SqlDbType.Int)).Value = islemId;
        cmd.Parameters.Add(new SqlParameter("@dovizTanim", SqlDbType.NVarChar)).Value = dovizTanim;
        cmd.Parameters.Add(new SqlParameter("@yapilanIslemTuru", SqlDbType.NVarChar)).Value = yapilanIslemTipi;

        using (var reader = cmd.ExecuteReader())*//error occurs here*
        {
            while (reader.Read())
            {
                kurToplamQuery = reader.GetDecimal(0);                    
            }
        }
        sqlConn.Close();
        return kurToplamQuery;

Thanks for your helps.

Advertisement

Answer

The stored procedure is called GetIslemDetayIdleri but the code is using a stored procedure called GetIslemIdleri. Maybe the latter has fewer parameters than the former and you meant to call the former in the code?

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement