Not all code paths return a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Srinivas45
    New Member
    • Jun 2007
    • 1

    Not all code paths return a value

    Hi,
    I am srinivas, i am getting error like:Not all code paths return a value
    I wrote 2 functions in a class which returns DataTable. after completion of 1 st function I got the currect result. whn I started writing 2 nd func I am getting this error, how can I eliminate this error.

    Thanks in advance...
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, srinivas. Welcome to TSDN!

    You're getting this warning because you have a conditional somewhere in your [typed] function that could cause the function to terminate without returning a value.

    What language are you coding in?

    Comment

    • karthickbabu
      New Member
      • Sep 2007
      • 33

      #3
      Using Try Catch Block

      But in Catch you wont catch and display the exception message. In Catch u throw the exception. I too got this warning i think its not error, am i right. In Function we return some values thats why we wont catch the exception.

      wrtie this code
      try

      your code

      catch
      Throw ex // important

      end try
      Originally posted by Srinivas45
      Hi,
      I am srinivas, i am getting error like:Not all code paths return a value
      I wrote 2 functions in a class which returns DataTable. after completion of 1 st function I got the currect result. whn I started writing 2 nd func I am getting this error, how can I eliminate this error.

      Thanks in advance...

      Comment

      • Newbie19
        New Member
        • Jun 2007
        • 122

        #4
        I read this post to try and solve why I get this error message, but it didn't work.

        Can any one help/advise me? Here is the function that causes the error:

        public String getOnTimeNames( )
        {
        try
        {
        String mConn = "Data Source = San-SQL; Initial Catalog = OnTimeTesting; Integrated Security = True; Max Pool Size = 500";
        String tSQL = "SELECT dbo.Defects.Def ectId AS OnTimeID, dbo.Defects.Nam e AS Name FROM dbo.Defects INNER JOIN dbo.Projects ON dbo.Defects.Pro jectId = dbo.Projects.Pr ojectId WHERE (dbo.Projects.P arentId = 126) ORDER BY dbo.Defects.Def ectId DESC";
        SqlConnection wConn = new SqlConnection(m Conn);
        SqlCommand mCmd = new SqlCommand(tSQL , wConn);
        wConn.Open();
        //readers for the data
        SqlDataReader Reader = mCmd.ExecuteRea der();
        while (Reader.Read())
        {

        OnTime_Name = (String)Reader["Name"];

        return OnTime_Name;


        }
        wConn.Close();
        }
        catch(ArgumentE xception )
        {
        return "An error occured whilst processing your request. Details follow: " ;
        }


        }
        Thanks,

        Newbie19

        Comment

        Working...