我想在使用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