I’m trying to do a simple update but I cannae for the life of me work out what I am doing wrong.
I have the following code which currently is not working – I’m getting not all code paths return a value.
public List<tblWeight> UpdateFeedback(string memberid, string locationid, int prikey, string feedback)
{
MyEntities updatefeedback = new MyEntities();
tblWeight newfeedback = (from q in updatefeedback.tblWeights
where q.MemberId == memberid &&
q.LocationId == locationid &&
q.PriKey == prikey
select q).SingleOrDefault();
updatefeedback.tblWeights.AddObject(newfeedback);
updatefeedback.SaveChanges();
}
Basically, I am attempting to update the Feedback column within tblWeight based upon the where clauses.
Can anyone point out where I am going wrong…drastically!!
- Sorry – the previous try/catch was legacy.
First off (for different reasons than your question), get rid of the block:
Second, you say that you return a
List<tblWeight>, but you aren’t doing it anywhere in the function. You either need to return NULL inside the try block at the end, or, preferably, a properly populatedList<tblWeight>structure.Either return the object you say you are going to return or change the function to return a “void” and return nothing.
As far as the exception handler goes, please read up a bit on best practices regarding handling exceptions. I won’t reiterate it in this post, since it’s been said many times before. I promise you that you’ll write code faster, write less code, and write better code if you do.