Tutorials to .com

Tutorials to .com » Dotnet » Foundation » Using the Data Access Application Block to be the return value of stored procedure

Using the Data Access Application Block to be the return value of stored procedure

Print View , by: iSee ,Total views: 15 ,Word Count: 308 ,Date: Mon, 24 Aug 2009 Time: 9:59 PM

Today, a friend asked me how the Data access application Block to get the return value of stored procedure, I found that his past writings did not mention this problem, and now to add a few specific solutions are as follows:

1, first of all establish a return value of the stored procedure, as an example, I built a simple 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
We need to get this program to return value 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, add a parameter of 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);
)
Through the above code in the program we will be able to get the return value of the stored procedure.

I used to write the article did not say there may be many places that would like to have more friends comments, thank you!

http://pw.cnblogs.com/archive/2006/06/19/429455.html


.NET foundation Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.