我有一个 SQL 存储过程,它在插入几条记录后将数字输出到一行。不过,该查询效果很好,并返回了我需要的内容。我想从查询中获取输出并将其读入标签。有人可以发光吗?谢谢。
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@spName", txt_Name.Text));
cmd.Parameters.Add(new SqlParameter("@spSource", txt_Source.Text));
cmd.Parameters.Add(new SqlParameter("@spDateCreated", txt_DateCreated.Text));
paramReturnNumber = cmd.Parameters.AddWithValue("@out", SqlDbType.NVarChar);
paramReturnNumber.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
查询:
ALTER PROCEDURE [dbo].[usps_InsertIntoMedia]
@spName varchar(100),
@spSource varchar(100),
@spDateCreated datetime
AS
SET NOCOUNT ON;
DECLARE @out nvarchar
BEGIN
INSERT INTO Media (Name, Source, DateCreated)
OUTPUT inserted.Number
VALUES(@spName,@spSource,@spDateCreated )
Select @out = Media.Number
FROM Media
END