grasshopper
New member
- Joined
- May 9, 2014
- Messages
- 2
- Programming Experience
- 10+
Hello All,
Below is a code C# example of sending an SQL DB email using sp_send_dbmail. Works great. However, the stored procedure is suppose to return an integer to denote if it was successful or failed.
My problem is getting that integer value. The info I have found says it returns an "integer value" but not as an OUTPUT variable. So I am lost. I have try ExecuteScalar and ExecuteQuery (@@Error, @Return, etc). As mentioned the email gets sent... I simply want to get the results code back to the C# code.
Probably something real easy... that I am not aware of.
Would anyone be so kind as to help me complete this code and get the return value from the SP run?
Thank you,
Eric
Errors on
Below is a code C# example of sending an SQL DB email using sp_send_dbmail. Works great. However, the stored procedure is suppose to return an integer to denote if it was successful or failed.
My problem is getting that integer value. The info I have found says it returns an "integer value" but not as an OUTPUT variable. So I am lost. I have try ExecuteScalar and ExecuteQuery (@@Error, @Return, etc). As mentioned the email gets sent... I simply want to get the results code back to the C# code.
Probably something real easy... that I am not aware of.
Would anyone be so kind as to help me complete this code and get the return value from the SP run?
Thank you,
Eric
using (SqlConnection PPPautoConnection = new SqlConnection(stringConn)) { Database db = ABCSqlDataHelper.CreateConnection(stringConn); DbCommand dbCommand = db.GetStoredProcCommand("msdb.dbo.sp_send_dbmail"); dbCommand.CommandTimeout = 1200; db.AddInParameter(dbCommand, "@profile_name", Profile_Name); db.AddInParameter(dbCommand, "@recipients", DbType.String, EmailTo); db.AddInParameter(dbCommand, "@from_address", DbType.String, EmailFrom); db.AddInParameter(dbCommand, "@subject", DbType.String, EmailSubject); db.AddInParameter(dbCommand, "@body", DbType.String, EmailBody); db.AddInParameter(dbCommand, "@body_format", Body_Format); db.ExecuteNonQuery(dbCommand); //var vResults = db.ExecuteScalar(dbCommand); results = Convert.ToInt32(db.GetParameterValue(dbCommand, "@@ERROR")); }
Errors on
results = Convert.ToInt32(db.GetParameterValue(dbCommand, "@@ERROR"));
Last edited by a moderator: