.net调用存储过程三 (含输出参数)
ALTER PROCEDURE [dbo].[test]
@BookId int output, @BookName varchar(50), @Author varchar(50) AS BEGIN SET NOCOUNT ON; INSERT INTO [book] ( [BookName] ,[Author] ) VALUES ( @BookName ,@Author ) set @BookId=@@IDENTITY; if @@rowcount<>1 BEGIN RETURN -1; END RETURN 0; END
转载自:http://www.189works.com/article-42994-1.html
自己的例子:
// 创建参数 SqlParameter[] parameters = { new SqlParameter("@BookId", SqlDbType.Int,4) , new SqlParameter("@BookName", SqlDbType.VarChar,50) , new SqlParameter("@Author", SqlDbType.VarChar,50) , new SqlParameter("retval", SqlDbType.Int,4) }; //设置参数类型 parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数 parameters[1].Value = "testName"; parameters[2].Value =“dsd”; // 给输入参数赋值 parameters[3].Direction = ParameterDirection.ReturnValue; // 设置为返回值 int a = SqlHelper.ExecuteNonQuery(SqlHelper.CONN_STRING_LC, CommandType.StoredProcedure, "test", parameters); Label1.Text = parameters[0].Value.ToString()+"---"+ parameters[3].Value.ToString();;
业精于勤荒于嬉 行成于思毁于随