您使用的是返回值(使用RETURN
语句)还是输出参数?如果是,那么ExecuteReader
是错误的选择。仅当SP使用SELECT
语句输出数据时,ExecuteReader才会返回数据。你应该使用带有返回参数的ExecuteNonQuery
。例如(从MSDN的引用),
CREATE PROCEDURE dbo.InsertCategory
@CategoryName nvarchar(15),
@Identity int OUT
AS
INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
SET @Identity = SCOPE_IDENTITY()
RETURN @@ROWCOUNT
和代码将
// Assumes connection is a valid SqlConnection.
SqlCommand command = new SqlCommand("InsertCategory" , connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter parameter = command.Parameters.Add(
"@RowCount", SqlDbType.Int);
parameter.Direction = ParameterDirection.ReturnValue;
parameter = command.Parameters.Add(
"@CategoryName", SqlDbType.NChar, 15);
parameter = command.Parameters.Add("@Identity", SqlDbType.Int);
parameter.Direction = ParameterDirection.Output;
command.Parameters["@CategoryName"].Value = "New Category";
command.ExecuteNonQuery();
Int32 categoryID = (Int32) command.Parameters["@Identity"].Value;
Int32 rowCount = (Int32) command.Parameters["@RowCount"].Value;
见http://msdn.microsoft.com/en-us/library/3btz0xwf.aspx
它的商店** d **程序 - 程序** **存储的SQL Server中(与商店无关) –
你能告诉我们你的存储过程的定义吗?你通过什么参数,你期望退出哪些参数? –