Cis Pa

Cis Pa

  • NA
  • 194
  • 22.9k

Stored procedure in Rest Web Api for updating the Database

Jun 10 2021 9:40 AM

Hi all,

I have stored procedure that will update multiple tables  and returnedvalue as 1.The parameters are passed through the Client application.

Here i updated the tables in DB so do i need to use PUT verb in my REST web api to call the SP and how to consume using PUT httpclient?

plz help

 [HTTPPUT]

public IHttpActionResultUpdateDB(string id,string name,string city,string country )
        {
            int ReturnValue = 0;
            SqlCommand cmd = new SqlCommand("SP_UPDATED", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            SqlParameter ret = new SqlParameter();
            ret.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.AddWithValue("@id", id);
            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@city", city);
            cmd.Parameters.AddWithValue("@country", country);
            ret.Direction = ParameterDirection.ReturnValue;
            cmd.Parameters.Add(ret);
            cmd.ExecuteNonQuery();
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                ReturnValue = (int)ret.Value;
            }
            catch (Exception ex)
            {

            }
            return ReturnValue;
        }
        

 


Answers (4)