I have this API, which calls a stored procedure to insert a value and it has few PRINT statements in the stored procedure
public class ConfirmJobController : ApiController
{
[HttpPost]
public IHttpActionResult Post(JobConfirmation confirmation)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
{
string outputMessage;
con.Open();
SqlCommand cmd = new SqlCommand("usp_PhoneApp_ConfirmBooking", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@p_jobId", confirmation.JobID);
cmd.Parameters.AddWithValue("@p_jobStatus", confirmation.JobStatus);
cmd.Parameters.AddWithValue("@p_createdDate", confirmation.CreatedDate);
cmd.ExecuteNonQuery();
con.InfoMessage += delegate (object sender1, SqlInfoMessageEventArgs e1)
{
outputMessage = e1.Message;
};
return outputMessage;
}
}
}
I would like get custom message from the stored procedure to the return value of the API. How can I do this?
currently the line return outputMessage gives an error with "use of unassigned variable and cannot implicitly convert string to IHttpActionResult"
Any help is greatly appreciated.