A stored procedure is returning 2 output parameter. I tried to catch them in DAL using DAAB but couldn't succeed. Actually control did not returned on next lines. Please guide me.
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
Haansi
Member
212 Points
428 Posts
DAAB how to get multiple output parameters ?
May 09, 2011 08:10 AM|LINK
A stored procedure is returning 2 output parameter. I tried to catch them in DAL using DAAB but couldn't succeed. Actually control did not returned on next lines. Please guide me.
using (DbCommand dbCommand = db.GetSqlStringCommand("p_AddLeaveApplication")) { dbCommand.CommandType = CommandType.StoredProcedure; db.AddInParameter(dbCommand, "@EmployeeId", DbType.Int16, leave.EmployeeId); db.AddInParameter(dbCommand, "@DateTo", DbType.Date,string.Format("'{0:yyyy-MM-dd HH:mm:ss}'", leave.DateTo)); db.AddInParameter(dbCommand, "@DateFrom", DbType.Date, string.Format("'{0:yyyy-MM-dd HH:mm:ss}'", leave.DateFrom)); db.AddInParameter(dbCommand, "@LeaveType", DbType.String, leave.LeaveType); db.AddOutParameter(dbCommand, "@Result", DbType.Int16, 1); db.AddOutParameter(dbCommand, "@LeaveId", DbType.Int16, 1); db.ExecuteNonQuery(dbCommand); LeaveId = Convert.ToInt16(db.GetParameterValue(dbCommand, "@LeaveId")); return result = Convert.ToInt16(db.GetParameterValue(dbCommand, "@Result")); }Best Regards,
Haansi
DarrellNorto...
All-Star
86665 Points
9634 Posts
Moderator
MVP
Re: DAAB how to get multiple output parameters ?
May 09, 2011 09:35 AM|LINK
If you are creating a DbCommand, you can use that to get the output params:
See if this article helps: http://www.devx.com/dotnet/Article/30910/0/page/4
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
Haansi
Member
212 Points
428 Posts
Re: DAAB how to get multiple output parameters ?
May 09, 2011 09:46 AM|LINK
Thanks DarrellNorton,
Please guide me one more thing.
It is when I need to catch 2 output parameters should I do like:
Best Regards,
Haansi
Jonathan She...
All-Star
31269 Points
3445 Posts
Re: DAAB how to get multiple output parameters ?
May 18, 2011 08:00 AM|LINK
Hi Haansi,
It won't execute your procedure when you call these lines.
Actually, it is called when you call db.ExecuteNonQuery(dbCommand); After this, all the output parameters are retrieved from the your procedure. You can see the steps from this link. http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.aspx
Best regards,
Jonathan
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework