The compiler complains about a missing return statement at the end of the function (he is not smart enough to detect that the end is never reached). You have three options:
- Ignore or suppress the warning (nonprofessional).
- Return the result at the end (move the return from the try block to the end).
- Return something at the end.
For the third case with comments for the second case:
public string InsertProduct(Product product)
{
try
{
GarageEntities db = new GarageEntities();
db.Products.Add(product);
db.SaveChanges();
return product.Name + "was succesfully inserted";
}
catch (Exception e)
{
return "Error:" + e;
}
return "";
}
[EDIT]
A tip for asking about such problems:
Always include the compiler code (CS0161 here) because this makes it clear what happened. However, searching the web for the message and/or code would have answered this too.