Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

namespace hospitalanagementsystem
{
    internal class utility
    {
        //get the connection string from app config file
        internal static string Connection()
        {
            //assuming failure in retrieval
            string returnValue = null;
            //look for the name in the connectionstring section
            ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["hospitalanagementsystem.Properties.Settings.constr"];

            //if found, return the connectionstring 
            if(setting!=null)
            {
                returnValue = setting.ConnectionString;
                return returnValue;
            }
            
        }
        
    }
}
in the above code i m having an error in the function name Coneection
the error says "not all code paths return a null value" please help me what should i do
thank you
Posted

You need a return statement at the end of the method for the case where setting is null.
 
Share this answer
 
C#
//get the connection string from app config file
internal static string Connection()
{
    //assuming failure in retrieval
    string returnValue = null;
    //look for the name in the connectionstring section
    ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["hospitalanagementsystem.Properties.Settings.constr"];

    //if found, return the connectionstring 
    if(setting!=null)
    {
        returnValue = setting.ConnectionString;
    }
   return returnValue; // moved this line to end, even in settings null you have return value now
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900