我想在使用SqlCommand參數的輸出參數中獲得一些值。command.Parameters.IsDirty的正值是什麼意思?
存儲過程運行正常,提供正確的記錄。我驗證了它在Sql Server上執行的過程,以及確保我做對了。
不過,我無法在服務器端獲得輸出,它總是沒有任何東西!在調試時,我看到IsDirty proeprty for command.Parameters設置爲True。
任何人都可以告訴它是什麼意思?
下面是一些代碼:
command.Parameters.Add("@count", SqlDbType.Int).Value = initialCountValue
command.Parameters("@count").Direction = ParameterDirection.Output
Dim dr = command.ExecuteReader()
newCountValue = Convert.ToInt32(command.Parameters("@count").Value)
下面是程序例如:
CREATE PROCEDURE [dbo].[usp_some_procedure]
@filter INT
@count INT output
AS
BEGIN
DECLARE @filtered_ids TABLE(row_num INT IDENTITY(1,1), id INT primary key)
INSERT INTO @filtered_ids (id)
SELECT id
FROM dbo.some_table
WHERE @filter = 0 OR table_field = @filter
ORDER BY id desc
SELECT @count = COUNT(*)
FROM @filtered_ids
SELECT some_table.*
FROM some_table
INNER JOIN @filtered_ids
ON some_table.id = @filtered_ids.id
END
請出示你的代碼。你如何在你的sql命令中聲明你的輸出參數? –
也請顯示存儲過程的SQL代碼。 –
改爲嘗試'ParameterDirection.InputOutput'。 – GSerg