CREATE PROCEDURE GetTextbookPreID
@id int,
@preID int output
AS
DECLARE
@queue int,
@parentID int,
@courseID int
BEGIN
select @queue=Queue ,@parentID=ParentID, @courseID=CourseID from Textbook where ID=@id
if @parentID<>0
if @queue==0
set @preID=-1
else select @preID=id from Textbook where CourseID=@courseID and ParentID=@parentID and Queue=(@queue-1)
else
if @queue=0
set @preID=-2
else select @preID=id from Textbook where CourseID=@courseID and ParentID=0 and Queue=(@queue-1)
RETURN @preID以上为据我的Oracle知识和查了点资料写的 好像编译不过去 有很多错误 又不知道到底该怎么写 求大家给给语法错误另外 能否给出一个在ASP.NET中获取返回值的方法
@id int,
@preID int output
AS
DECLARE
@queue int,
@parentID int,
@courseID int
BEGIN
select @queue=Queue ,@parentID=ParentID, @courseID=CourseID from Textbook where ID=@id
if @parentID<>0
if @queue==0
set @preID=-1
else select @preID=id from Textbook where CourseID=@courseID and ParentID=@parentID and Queue=(@queue-1)
else
if @queue=0
set @preID=-2
else select @preID=id from Textbook where CourseID=@courseID and ParentID=0 and Queue=(@queue-1)
RETURN @preID以上为据我的Oracle知识和查了点资料写的 好像编译不过去 有很多错误 又不知道到底该怎么写 求大家给给语法错误另外 能否给出一个在ASP.NET中获取返回值的方法
==
这个是输出参数,不是返回值
2、SQL里判断相等是=号,不是==号
3、asp.net获取返回值也很简单。直接取那个标记为返加值的参数的值,不过它是Object类型的,要转一下就OK了。
如何调用存储过程的返回值,我想,网上的资料很多。
{
conn.Open();
SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
MyCommand.Parameters["@a"].Value = 20;
MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
MyCommand.Parameters["@b"].Direction = ParameterDirection.Output;
MyCommand.ExecuteNonQuery();
Response.Write(MyCommand.Parameters["@b"].Value.ToString());
}
// @a int,
// @b int
//AS
// return @a + @b
//GO
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
conn.Open();
SqlCommand MyCommand = new SqlCommand("MYSQL", conn);
MyCommand.CommandType = CommandType.StoredProcedure;
MyCommand.Parameters.Add(new SqlParameter("@a", SqlDbType.Int));
MyCommand.Parameters["@a"].Value = 10;
MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
MyCommand.Parameters["@b"].Value = 20;
MyCommand.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
MyCommand.Parameters["@return"].Direction = ParameterDirection.ReturnValue;
MyCommand.ExecuteNonQuery();
Response.Write(MyCommand.Parameters["@return"].Value.ToString());
RETURN @preID这句
if @queue==0
改成
if @queue = 0
begin
if @queue=0
set...
end
如果是 return @preID 该怎么获取值
Output
MyCommand.Parameters.Add(new SqlParameter("@b", SqlDbType.Int));
MyCommand.Parameters["@b"].Direction = ParameterDirection.Output;
ReturnValue
MyCommand.Parameters.Add(new SqlParameter("@return", SqlDbType.Int));
MyCommand.Parameters["@return"].Direction = ParameterDirection.ReturnValue;