熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ado.net獲取存儲過程的返回值

2022-06-13   來源: .NET編程 

  假設有存儲過程如下:

  

  CREATE PRoc sp_uptmp @tmpName varchar()@srcPos varchar()

  as

  Begin TRAN

  insert into t_template values(@tmpName@srcPos)

  COMMIT

  return isnull(@@identity)

  GO

  

  在 裡面獲取返回值的方法為(c#):

  

  SqlConnection dbconn = new SqlConnection(connStr);

  SqlCommand cmd = new SqlCommand(sp_uptmpdbconn);

  cmdCommandType = CommandTypeStoredProcedure;

  SqlParameter tmpName = cmdParametersAdd(@tmpNameSqlDbTypeVarChar);

  SqlParameter srcPos = _cmdParametersAdd(@srcPosSqlDbTypeVarChar);

  SqlParameter rtnval = cmdParametersAdd(rvalSqlDbTypeInt);

  tmpNameDirection = ParameterDirectionInput;

  srcPosDirection = ParameterDirectionInput;

  rtnvalDirection = ParameterDirectionReturnValue;

  tmpNameValue = ;

  srcPosValue = ;

  dbconnOpen();

  cmdExecuteNonQuery();

  dbconnClose();

  tmpid = (int)rtnvalValue;  //此處即為返回值


From:http://tw.wingwit.com/Article/program/net/201311/13773.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.