R
RAM
Hello,
I am learning .NET 2.0. I am trying to call a stored procedure:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "NextDocumentNumber";
cmd.Transaction = t;
cmd.Connection = c;
int n = (int)cmd.ExecuteScalar(); // here problem
The problem is that ExecuteScalar returns null although executed in SQL
Server Management Studio it returns some integer value. I don't understand
why because transaction t and connection c are correct. Below the code of
stored procedure:
ALTER PROCEDURE [dbo].[NextDocumentNumber]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @n int
SELECT @n = COUNT(*) FROM Documents
IF @n = 0
BEGIN
SELECT @n =StartOfRange FROM Numbering
WHERE Year = YEAR(GETDATE())
RETURN @n
END
SELECT @n = MAX(Number) FROM Documents
WHERE Year = YEAR(GETDATE()) AND Movement = 'PZ'
RETURN @n + 1
END
Could you help me please to solve the problem? Thank you very much!
/RAM/
I am learning .NET 2.0. I am trying to call a stored procedure:
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "NextDocumentNumber";
cmd.Transaction = t;
cmd.Connection = c;
int n = (int)cmd.ExecuteScalar(); // here problem
The problem is that ExecuteScalar returns null although executed in SQL
Server Management Studio it returns some integer value. I don't understand
why because transaction t and connection c are correct. Below the code of
stored procedure:
ALTER PROCEDURE [dbo].[NextDocumentNumber]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @n int
SELECT @n = COUNT(*) FROM Documents
IF @n = 0
BEGIN
SELECT @n =StartOfRange FROM Numbering
WHERE Year = YEAR(GETDATE())
RETURN @n
END
SELECT @n = MAX(Number) FROM Documents
WHERE Year = YEAR(GETDATE()) AND Movement = 'PZ'
RETURN @n + 1
END
Could you help me please to solve the problem? Thank you very much!
/RAM/