erro estupido c# acho eu

alfinete

Power Member
c#
Código:
private bool [COLOR=Blue]Savequestiontrainees[/COLOR](string [] TxtBox,System.Web.UI.WebControls.GridView grv,string TypeQuery)
            {
                string values = string.Empty;
                string Valuesids = string.Empty;
                bool res = true;

                ENB.BussinessLayer.EnbETAnswersTrainees oQuestionstrainee = new ENB.BussinessLayer.EnbETAnswersTrainees();

                try
                {
                    foreach (GridViewRow row in grv.Rows)
                    {
                        
                        //string teste = row.Cells[3].Text;
                        int value =0, value1=0, value2=0, value3 = 0;

                        int idquestion = 0;

                        string teste = TxtBox[0].ToString();
                        string Valuetxt = ((TextBox)row.Cells[2].FindControl(TxtBox[0].ToString())).Text;
                        string Valuetxt2 = ((TextBox)row.Cells[3].FindControl(TxtBox[1].ToString())).Text;
                        string Valuetxt3 = ((TextBox)row.Cells[4].FindControl(TxtBox[2].ToString())).Text;
                        string Valuetxt4 = ((TextBox)row.Cells[5].FindControl(TxtBox[3].ToString())).Text;


                        if (row.Cells[1].Text != " ")
                        {

                            idquestion = Int32.Parse(row.Cells[6].Text);

                            //// valor linha a linha 
                            if (!string.IsNullOrEmpty(Valuetxt))
                               value = Int32.Parse(Valuetxt);
                            else if (string.IsNullOrEmpty(Valuetxt))
                               value = 0  ;

                           if (!string.IsNullOrEmpty(Valuetxt2))
                               value1 = Int32.Parse(Valuetxt2);
                           else if (string.IsNullOrEmpty(Valuetxt2))
                               value1 =0;

                           if (!string.IsNullOrEmpty(Valuetxt3))
                               value2 = Int32.Parse(Valuetxt3);
                           else if (string.IsNullOrEmpty(Valuetxt3))
                               value2 = 0;

                           if (!string.IsNullOrEmpty(Valuetxt4))
                              value3 = Int32.Parse(Valuetxt4);
                           else if (string.IsNullOrEmpty(Valuetxt4))
                              value3 = 0;

                              oQuestionstrainee.ClassIdFormees = Int32.Parse(Session["class"].ToString() );
                              oQuestionstrainee.QuestionIdFormees = idquestion ;
                              oQuestionstrainee.TrainerIdFormees = Int32.Parse(ddlTrainers.SelectedValue);

                              oQuestionstrainee.Res1 = value;
                              oQuestionstrainee.Res2 = value1;
                              oQuestionstrainee.Res3 = value2;
                              oQuestionstrainee.Res4 = value3;

                              oQuestionstrainee.SuggestionsReviews = txtSuggestionsReviews.Text;
                              oQuestionstrainee.ImportantTopics = txtImportantTopics.Text;
                              oQuestionstrainee.DevelopingThemes = txtDevelopingThemes.Text;
                              oQuestionstrainee.OtherTopics = txtOtherTopics.Text;
                              oQuestionstrainee.Positiveaspects = txtPositiveaspects.Text;
                              oQuestionstrainee.Improveaspects = txtImproveaspects.Text;
                              oQuestionstrainee.Suggestions = txtSuggestions.Text;
                              oQuestionstrainee.ChangingPractice = txtChangingPractice.Text;
                              oQuestionstrainee.Comments = txtComments.Text;

                           
                              if (TypeQuery == "Insert")
                              {
                                  if (oQuestionstrainee.EnbETAnswersTraineesINS() == false)
                                   res = false;
                              }
                              else
                              {
                               if (oQuestionstrainee.EnbETAnswersTraineesUPD() == false)
                                    res = false;
                                 
                              }
                               
                        }
                       
                        if (res == false)
                            break;
                       
                        
                    }
                    return res;  
                    
                }
                catch (Exception ex)
                {
                    string err = ex.Message;  
                }
                finally
                {

                    oQuestionstrainee  = null;
                   
                }
               
            }


erro

Código:
Error    3    'StepAhead.Web.EnbEvaluationTraining.EnbEvaluationTrainingWuControl.wucEnbEvaluationTrainingTrainee.Savequestiontrainees(string[], System.Web.UI.WebControls.GridView, string)': not all code paths return a value    C:\alfredo\my projects\sourcesave\enb_framework\development\project\ENBFramework\EnbEvaluationTraining\EnbEvaluationTrainingWuControl\wucEnbEvaluationTrainingTrainee.ascx.cs    524    26    ENBFramework

gostava de saber porque esta a dar este erro sublinhando a azul o que esta a letra azul na função

???
 
se houver exception ele vai pro catch e daí não devolve nada.
solução mete o return depois do scoop do finally (mm no final da função) assim aconteça o que acontecer ele devolve sempre.
 
ja o puz no fim depois do fim do finaly e ele da problemas na mesma

Isso é um bocado impossível... repara que o erro que dá nem é de runtime, é mesmo um erro de compilação. Este erro significa que nem todos os caminhos que a tua função pode tomar estão a devolver valores.

À primeira vista, esse é um deles (e o único aparentemente). O programa manda uma excepção dentro do teu ciclo, é mandado para o catch (não tem return), depois vai ao finally (também sem return) e por fim acaba a execução da função sem nunca ter devolvido valor.
 
Back
Topo