hi,
I am making restful api through which i want to insert data in sql db i have this code but its not working please advice what i am doing wrong
[WebInvoke(Method="Post", RequestFormat=WebMessageFormat.Json, UriTemplate= "AddCountry/{countryname}", ResponseFormat= WebMessageFormat.Json,BodyStyle =WebMessageBodyStyle .Wrapped)]
public void addcountry(string countryname)
{
string constring = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Country (CountryName) VALUES (@CountryName)", con))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@CountryName", countryname);
con.Open();
int rowsAffected = cmd.ExecuteNonQuery();
con.Close();
}
}
}