Error: not all code paths return a value

Discussion in 'MCAD' started by airwalker, Jul 4, 2006.

  1. airwalker

    airwalker Guest

    Hi guys. Im creating a webservive, when I try to build the solution, I got
    the following message:

    not all code paths return a value

    this is my code: (note: the line that begins public string MakeReservation
    is what is
    causing the error, when I build the solution "MakeReservations" is highlighted

    public class MyWebService
    {
    [WebMethod]
    public string MakeReservations(int ID, string DateFrom, string
    DateTo, string TimeFrom, string TimeTo, string Destination, int ContactID)
    {
    String sqlStatement = "";
    try
    {
    SqlConnection poly = new SqlConnection();
    poly.ConnectionString = ConfigurationSettings.AppSettings["ConnString3"];


    poly.Open();
    DataSet dsID = new DataSet();
    SqlCommand comAdoCommand = new SqlCommand();
    comAdoCommand.Connection = poly;
    comAdoCommand.CommandText = "Select * from AppointmentDetails";

    // create data adapater
    SqlDataAdapter adosc = new SqlDataAdapter();
    adosc.SelectCommand = comAdoCommand;
    adosc.Fill(dsID,"AppointmentDetails");
    DataView dview = new DataView(dsID.Tables["AppointmentDetails"]);
    dview.RowStateFilter = DataViewRowState.CurrentRows;

    // code for creating reservation
    int conid=0;
    foreach(DataRowView drview in dview)
    {
    conid = Int32.Parse(drview["AppointmentID"].ToString());
    }
    if(conid>0)
    {
    conid++;
    }
    else
    {
    conid = 1;
    }

    SqlConnection adcConnection = new SqlConnection();
    adcConnection.ConnectionString =
    ConfigurationSettings.AppSettings["ConnString2"];
    adcConnection.Open();
    sqlStatement = "Insert into AppointmentDetails values(" + ID + "," +
    conid + ",'" + DateFrom + "'," + DateTo + "'," + TimeFrom + "','" +
    TimeTo + "','" + Destination + "'," + ContactID + ")";
    conid++;

    SqlCommand cSQLStatement = new
    SqlCommand(sqlStatement,adcConnection);
    cSQLStatement.CommandText = sqlStatement;
    cSQLStatement.ExecuteNonQuery();

    }

    catch(Exception e)
    {
    return e.ToString();
    }
     
    airwalker, Jul 4, 2006
    #1
    1. Advertisements

  2. airwalker

    neil.weller Guest

    Your problem is that "not all code paths RETURN a value" (RETURN - HINT
    HINT HINT).

    I am not going to spell out the solution as you will learn far more by
    taking the following steps:
    1. Look at help to see what the error means
    2. Consider what the function (HINT) is supposed do when it completes
    3. You may also want to do some reading on Exception handling and how
    to deal with them effectively and securely (if your code is trying to
    bubble up the exception then you should be rethrowing it...)

    You may think I am being awkward but that is a pretty basic error, I
    haven't been through all of the code, just the obvious parts.

    Hope this helps, reply again if you still have trouble.
    Neil
     
    neil.weller, Jul 4, 2006
    #2
    1. Advertisements

  3. airwalker

    neil.weller Guest

    You know what. I have just been thinking about your question and I
    noticed that you passed one of the exams recently, 70-315 wasn't it?

    This is gonna sound really harsh but you are an example of why it was
    so important that they changed the certifications. Your problem is
    such a basic problem that it is quite shocking that you cannot (a)
    figure it out and (b) find the answer just by doing some basic problem
    solving/searching.

    You need to do a lot more work before you should be thinking about
    other exams and if I were you I would switch and do the .Net 2.0 exams,
    to pass those you need to know the basics.

    Again, I know this sounds harsh, but having the exams isn't going to
    get you anywhere if you cannot figure that one out.
    Neil
     
    neil.weller, Jul 4, 2006
    #3
  4. airwalker

    airwalker Guest

    Well thanks for the "advice", but ur assuming the person who asked the
    question in this instance is the same person passed 70-315 a few weeks ago,

    several people use this user name for ease, as this computer has problems
    with this website when trying to login, so to save time we use one user name
    & password which is set to be remembered.

    thanks again, but next time please dont assume.
     
    airwalker, Jul 5, 2006
    #4
  5. airwalker

    JesseDart Guest

    wow, that was a vey rude response there neil.

    I live in a house with 3 other students, and we all use the name login name
    for message boards and forums like this one, and we are all differently
    experienced when it comes to programming. So airwalker was right in saying
    you that shouldnt assume.

    We all ask a variety questions from highly technical questions to simple
    beginner questions.

    I've been programming for 4 years, and sometimes I get stuck on simple
    problems, specially when its a problem that may not have happened for a long
    time.

    If somebody leaves a question here, then you should advise them, not insult
    them or talk to them like they are idiots, if you want to insult people then
    go to a yahoo chat room.

    all the best.

    Jess.
     
    JesseDart, Jul 5, 2006
    #5
  6. airwalker

    neil.weller Guest

    Nah, I stand by my reply. It is accurate, If he wasn't studying for
    the exams and just had a problem with the code then he would have used
    a rather more appropriate news group. If you think I was rude then you
    are a bit thin skinned.

    I still stand by what i said, he posts here on a certification group
    and asks a basic question. Also, if you guys cannot figure out how to
    set up multiple addresses (google groups maybe?) then you have other
    issues.

    So, thanks for your opinion, you can have yours and I will have mine,,,
    Neil
     
    neil.weller, Jul 5, 2006
    #6
  7. airwalker

    neil.weller Guest

    By the way, they key point I was trying to make is that sometimes the
    key to the IT world is not having an encylopedic knowledge, it is
    knowing where to look. Typing that error into google would have got
    him an answer instantly.

    Neil
     
    neil.weller, Jul 5, 2006
    #7
  8. airwalker

    Cerebrus Guest

    Well, well, well !

    I think Neil was right on a few points atleast.

    1. This is a very basic error and the solution can be easily found upon
    googling with the error message.
    2. The error message is self-explanatory.
    3. I think that multiple people using the same username is itself
    something silly, since your username is what we know you by. I, for
    one, had no idea that the name "airwalker" could represent different
    people with different skillsets. For instance, assume that one person
    posting with that name asked a question, and I answered him. Then the
    next day, another person posting by the same name, asks a similar
    question in a different thread. My response would obviously be to
    inquire if he didn't understand my previous response to him.

    Thus, it is natural to assume that one username belongs to one person.

    On the other hand, the harsh tone in his post, was uncalled for.

    Just my 2c.
     
    Cerebrus, Jul 5, 2006
    #8
  9. airwalker

    bogdip Guest

    Hi,

    The problem to your error message is that your method specifies that it
    returns a string (public string ...) but it does not returns any value after
    completing its execution. (I haven't seen any "return myString" or such in
    the method code)

    And for neil:

    If you shall try not to judge other people so much you will feel better with
    yourself.
    Even if he pass one exam, what's you problem, you can't sleep because
    someone asked a low level technical question? It hapens sometimes.
     
    bogdip, Jul 5, 2006
    #9
  10. airwalker

    neil.weller Guest

    I don't have a problem, I sleep fine thanks and I feel absolutely
    wonderful about myself, I have a slight twinge in my knee from running
    but that will ease ;-). And I will help anyone out with any problem
    they have, but if you look at it in context then it helps.

    If this was asked in the c#.programming group then I would have
    answered with the same pointers, but not the rant about certification
    etc. However, because this is a newsgroup about MCAD and airwalker (or
    rather the airwalker id) has been asking a few questions about
    webservices and also posting about having passed an exam, then it leads
    to the colnclusion (quite logical in my opinion) that there is a guy
    that has passed an exam but doesn't have a clue about the fact that a
    method that states that it returns a string needs to return a string.

    I gave him enough info to work out the solution for himself, which is
    what I would do with my the dev team at work. A lesson learnt for
    oneself is more likely to stay in your head than if someone just says,
    you haven't returned a value. Although with this thread he probably
    will now never forget.

    Yes, my tone was harsh, and I acknowledged that myself in my message, I
    won't apologise for it because my point is valid, with the facts I had
    at hand.

    I am dealing daily with people who have passed this exam or that exam
    and then they come up with issues like that one. It makes you realise
    that with all of the brain dumps and the relative ease of the exams,
    the fact that a lot of it is conceptual rather than at the language
    level, that people have got MCAD or MCP and they don't know the first
    thing about how to actually do the job at hand. The new track changes
    that somewhat and I think it is for the better. It is frustrating
    though, I have been an MCP of one form or another since 1994 so I am a
    touch protective (maybe overly so, I admit that) when I think it is
    getting devalued.

    Neil

    P.S. He does return something but only in the catch block, which is
    why I suggested reading up on exception handling, the Richter book has
    a great section on it. Also some reading on Security best practices
    and exception handling would be a good idea.
     
    neil.weller, Jul 5, 2006
    #10
  11. airwalker

    airwalker Guest

    Thanks, I did find the solution and I now know where I was going wrong. The
    code I was using was from the mcad/mcsd self paced training book, when I
    tried to build the solution and it didnt work I wasnt sure if the the code in
    the book was flawed or if I was missing something. It turned out the the code
    in the book is incorrect, but I didnt think that this would be the problem.

    I have used other methods to work with remote databases and they havnt
    included the return statement.

    I wasnt asking for an answer to my problem, I just wanted to know if anybody
    could see where I was going wrong, as I copied the code directly from the
    book, and therefore assumed that the code would be right, as it was in the
    book.
     
    airwalker, Jul 5, 2006
    #11
  12. airwalker

    neil.weller Guest

    Glad to hear you sorted it? Was that the MSPress book? If so then you
    should report it to MS, there is a link on the MSPress part of the MS
    Site. I seem to recall you go to the book you have and there is a link
    to report a bug. I've done it a few times and they generally get added
    to the errata.

    Neil
     
    neil.weller, Jul 5, 2006
    #12
  13. airwalker

    Simon Hart Guest

    He is using Microsoft CDO on Windows 2000 so it is probebly not worth the
    hastle to keep changing users as it is comming from a rich smart client not
    google groups or web browser as they are crap for NNTP posting. Look at the
    header.

    Your points are valid but you are being a dick. In future recommend a more
    appriopriate newsgroup to post.

    Simon.
     
    Simon Hart, Jul 5, 2006
    #13
  14. July 11, 2006

    Although I wouldn't normally post my opinion on this "issue", I'm going
    to...

    Even the most experienced developers don't know each and every error... and
    therefore it is MUCH better for asking about something than to spend hours
    and hours trying to figure it out (or even 20 minutes when it could be told
    to you in 20 seconds). So frankly, whether it is a beginner asking the
    question, or a developer with 30 years experience, they all deserve a kind,
    thoughtful, and respectful answer.

    Also, there is no such thing as a stupid question! Even one of the best beta
    program managers said she would throw anyone off the beta who said his/her
    question was a stupid question.

    So frankly, JesseDart & Airwalker & Simon, I appreciate your kind and
    non-condescending attitude. :) --- I can assure you that many more people
    also appreciate it!!
    --
    Joseph Bittman
    Microsoft Certified Solution Developer
    Microsoft Most Valuable Professional -- DPM

    Web Site/Blog: http://CactiDevelopers.ResDev.Net/
     
    Joseph Bittman MVP MCSD, Jul 11, 2006
    #14
  15. airwalker

    RYoung Guest

    It's not so much that the method did not have a return statement for a
    successful call, it's that if it failed, it was gonna do this:

    catch ( Exception e )
    {
    return e.ToString();
    }

    there's something fundamentally wrong with that in my opinion.

    Ron
     
    RYoung, Jul 11, 2006
    #15
  16. airwalker

    RYoung Guest

    <snip>
    I am not going to spell out the solution as you will learn far more by
    taking the following steps:
    1. Look at help to see what the error means
    2. Consider what the function (HINT) is supposed do when it completes
    3. You may also want to do some reading on Exception handling and how
    to deal with them effectively and securely (if your code is trying to
    bubble up the exception then you should be rethrowing it...)
    </snip>

    I agree, that is very good advice. After following it, the person will 1)
    solve the problem, and 2) know a bit more about researching.

    Sorry for jumping in late, I just agreed with your original post off the
    bat.

    Ron
     
    RYoung, Jul 11, 2006
    #16
  17. airwalker

    Cerebrus Guest

    Joseph,

    If you only look at Neil's first post, you will see that he did try to
    help out the OP. Instead of giving a direct answer and closing the
    matter, he tried to make the OP research the problem. That would give
    reveal far more information and help him to learn.

    In my opinion, since he took an effort and showed personal concern, it
    isn't fair to blame him outrightly.
     
    Cerebrus, Jul 12, 2006
    #17
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.