///<summary>
///c#code,获得SQL-server存储过程的返回值
///<summary>
SqlParameter[] sp = new SqlParameter[5];
sp[0]=new SqlParameter("@Name",SqlDbType.VarChar);
sp[0].Value=this.TextName.Text;
sp[1]=new SqlParameter("@Text",SqlDbType.Text);
sp[1].Value=this.TextTxt.Text;
sp[2]=new SqlParameter("@Comment",SqlDbType.Text);
sp[2].Value=this.TextComment.Text;
sp[3]=new System.Data.SqlClient.SqlParameter("ReturnValue",System.Data.SqlDbType.Int,4,System.Data.ParameterDirection.ReturnValue,false,0,0,string.Empty,DataRowVersion.Default,null);
//参数"ReturnValue",System.Data.ParameterDirection.ReturnValue声明此参数为返回值。
sp[4]=new SqlParameter("@Type",SqlDbType.Int);
sp[4].Value=int.Parse(this.ClickBox.SelectedItem.Value);
_SQL.ExecuteSP("us_styletextnew",sp);
//使用sp[3].Value.ToString()即可!
存储过程为:
CREATE PROCEDURE [dbo].[us_styletextnew]
@id int=0,
@Name varchar(50),
@Text text,
@Comment text,
@Type int
AS
SET NOCOUNT ON
IF not EXISTS(SELECT [Name] FROM [dbo].[iStyle] WHERE [Name] = @Name)
BEGIN
INSERT INTO
[dbo].[iStyle]
([Name],
[Text],
[Comment],
[Type])
VALUES
(@Name,@Text,@Comment,@Type)
SET @id = SCOPE_IDENTITY()
END
RETURN @id
GO
希望对刚学存储过程的朋友有点帮助!