my stored procedure:
create Procedure spSetUser ( @Name NVarchar(50), @OrganicTitle NVarchar(30), @UserName NVarchar(20), @Password NVarchar(16), @Result Int Output ) As Begin Set @Result = -1 If Not Exists(Select UserId From dbo.Users Where UserName=@UserName ) Begin Insert Into dbo.Users (Name,OrganicTitle,UserName,[Password]) Values(@Name,@OrganicTitle,@UserName,@Password) Set @Result = SCOPE_IDENTITY() End Return End Go
and my class (in the microfiche corporate library):
[DataObjectMethod(DataObjectMethodType.Insert)] public Int32 SetUser(UserFieldSet Data) { Int32 Result = 0; object[] values = new object[] { Data.Name, Data.OrganicTitle, Data.UserName, Data.Password, Data.UserId }; Result = Db.ExecuteNonQuery("spSetUser", values); return Result; }
The result is checked for the execution of the stored procedure, but I want to get the value @Result (the output parameter of the procedure), how can I get it?
UserFieldClass:
public class UserFieldSet { public Int32 UserId; public String Name; public String OrganicTitle; public String UserName; public String Password; }
Tip. I know I have to use this code to get @Result:
public Int32 SetUser(UserFieldSet Data) { Int32 Result = 0; DbCommand DbCmd = Db.GetStoredProcCommand("spSetUser"); Db.AddInParameter(DbCmd, "@Name", DbType.String, Data.Name); Db.AddInParameter(DbCmd, "@OrganicTitle", DbType.String, Data.OrganicTitle); Db.AddInParameter(DbCmd, "@UserName", DbType.String, Data.UserName); Db.AddInParameter(DbCmd, "@Password", DbType.String, Data.Password); Db.AddOutParameter(DbCmd, "@Result", DbType.Int32, Int32.MaxValue); Db.ExecuteNonQuery(DbCmd); Result = (Int32)Db.GetParameterValue(DbCmd, "@Result"); return Result; }
But I can get this with this method:
Result = Db.ExecuteNonQuery("spSetUser", values);