Tutorials ADO.NET Core Tutorial
Return Values — Complete Guide
Return Values — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ADO.NET Core Tutorial on Toolliyo Academy.
On this page
ADO.NET Core Tutorial · Lesson 26 of 100
Return Values
Foundations ✓ → SQL & safety → Production → Projects
SQL & safety · 2 — Procs, tx, performance · ~6 min · Module 3: Stored Procedures
What is this?
Procedures can RETURN an int status; read it with ParameterDirection.ReturnValue.
Why should you care?
ShopNest payment procs often return 0=ok, non-zero=business error without throwing.
See it live — copy this example
Use a .NET console or API project with SQL Server LocalDB. Run dotnet run after pasting.
var ret = cmd.Parameters.Add("@RETURN_VALUE", SqlDbType.Int);
ret.Direction = ParameterDirection.ReturnValue;
await cmd.ExecuteNonQueryAsync(ct);
Console.WriteLine((int)ret.Value!); // 0 ok
What happened?
- Add return parameter before execute.
- Convention: 0 success.
- Prefer THROW for unexpected failures.
Practice next
- Proc RETURN 0/1.
- Read return value.
- Map codes to exceptions.
- Return 2 for insufficient funds.
- Branch in C# on code.
Remember
ReturnValue direction. 0 = success convention. Map to domain errors.
ShopNest pay return codes
usp_CapturePayment returns status ints.
Outcome: API shows precise business errors.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!