access|application| Stored Procedures
Today, a friend asked me how to get the return value of the stored procedure in the Data Access Application block, and I found that I did not mention this in my previous article, and now to add, the specific solution is as follows:
1, first set up a stored procedure with a return value, as an example, I will simply build a stored procedure, as follows:
CREATE proc Test
(
@id int
)
As
DECLARE @flag int
SELECT * from person where id= @id
If @ @rowcount > 0
Set @flag =1
Else
Set @flag =0
Return @flag
The method we want to get this return value in the program is as follows:
[TestMethod]
public void Testreturnvalue ()
{
Database db = Databasefactory.createdatabase ();
DbCommand Dbcomm = db. Getstoredproccommand ("test");
Db. Addinparameter (Dbcomm, "@id", dbtype.int32,1);
The key here is to add a parameter to the type returnvalue
Db. Addparameter (Dbcomm, "@RETURN_VALUE", dbtype.string, ParameterDirection.ReturnValue, "", DataRowVersion.Current, NULL);
Db. ExecuteNonQuery (Dbcomm);
int testvalue = (int) Dbcomm. parameters["@RETURN_VALUE"]. Value;
Assert.AreEqual (TestValue, 1);
}
With the above code we can get the return value of the stored procedure in the program. Previously written articles may have a lot of places did not say, I hope to have more friends to make comments, thank you!