MikeMCSD
asked on
How to Return a success or fail code from a Stored Procedure?
I'm running a stored procedure from code and I want to know if it completed succesfully:
string connectionString = ConfigurationManager.Conne ctionStrin gs["NopSql Connection "].Connect ionString;
using (var conn = new SqlConnection(connectionSt ring))
using (var command = new SqlCommand("Import_Update" , conn) {CommandType = CommandType.StoredProcedur e})
{
conn.Open(); command.ExecuteNonQuery();
conn.Close();
// Return a success or fail code
}
ALTER PROCEDURE Import_Update
AS
BEGIN
SET NOCOUNT ON;
UPDATE . . .
..........
-- Return a success or fail code
END
What is the best way to do this? thanks
string connectionString = ConfigurationManager.Conne
using (var conn = new SqlConnection(connectionSt
using (var command = new SqlCommand("Import_Update"
{
conn.Open(); command.ExecuteNonQuery();
conn.Close();
// Return a success or fail code
}
ALTER PROCEDURE Import_Update
AS
BEGIN
SET NOCOUNT ON;
UPDATE . . .
..........
-- Return a success or fail code
END
What is the best way to do this? thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Like!
liek on Success - Select 'true'
on Failuer - Select 'false'
Thanks!
string connectionString = ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString;
using (var conn = new SqlConnection(connectionString))
using (var command = new SqlCommand("Import_Update", conn) {CommandType = CommandType.StoredProcedure})
{
conn.Open();
returnValue = cmd.ExecuteScalar();
conn.Close();
// Return a success or fail code
}
Make sure your Stored proceudre return vale liek on Success - Select 'true'
on Failuer - Select 'false'
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks all
ASKER