gpt4 book ai didi

c# - 将参数传递给C#中的存储过程

转载 作者:太空狗 更新时间:2023-10-30 00:21:25 27 4
gpt4 key购买 nike

如何将三个参数a传递给sql中的存储过程?

这是我的错误:过程或函数 GetIslemIdleri 指定的参数太多。

这是我的存储过程:

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

这是我的代码:

        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;

感谢您的帮助。

最佳答案

存储过程称为 GetIslemDetayIdleri,但代码使用的是名为 GetIslemIdleri 的存储过程。也许后者的参数比前者少,你打算在代码中调用前者?

关于c# - 将参数传递给C#中的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5419861/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com