我在 SQL 中有一个函数,它在 SQL 管理中执行时返回正确答案,这是我的函数
ALTER FUNCTION [dbo].[Dore1]
(@First NVARCHAR(50), @second NVARCHAR(50))
RETURNS INT
AS
BEGIN
DECLARE @Tedad INT
SET @tedad = (SELECT COUNT(sh_gharardad)
FROM OrgGharardad
WHERE OrgGhAghdDate BETWEEN @First
AND @second)
RETURN @Tedad
END
但是当我在我的 c# 程序中使用它时,它会在此代码中返回 0(零)值。我在哪里写错了?
int dore1, dore2;
ConnectDb Contact = new ConnectDb();
Contact.connect();
SqlCommand Cmd = new SqlCommand("dore1", cnn);
SqlCommand Cmd2 = new SqlCommand("dore2", cnn);
Cmd.CommandType = CommandType.StoredProcedure;
Cmd2.CommandType = CommandType.StoredProcedure;
cnn.Open();
Cmd.Parameters.AddWithValue("@First", txt_1_aghaz.Text);
Cmd.Parameters.AddWithValue("@Second", txt_1_payan.Text);
dore1=Convert.ToInt32( Cmd.ExecuteScalar());
Cmd2.Parameters.AddWithValue("@First2", txt_2_aghaz.Text);
Cmd2.Parameters.AddWithValue("@second2", txt_2_payan.Text);
dore2= Convert.ToInt32( Cmd2.ExecuteScalar());
CreateChart(dore1, dore2);
cnn.Close();