Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my class file i have following code:

C#
public Double GetScalarRes(String CmdStr, SqlCommand SqlCmd, String strConArc)
    {
        // This function return only 1 value i.e. double value.
        // It takes Query String and execute it on SQL server and returns only one value.

        double Res = 0;


        try
        {
            // checking whether connection string from web.config file is "strConString".
            // accordingly setting the connection object.

            if (strConArc == "strConString1")
            {
                con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strConString1"]);
            }
            else
            {
                con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strConString"]);
            }
            con.Open();

            if ((SqlCmd != null))
            {
                SqlCmd.Connection = con;

                // returns only 1 value.
                //Res = Convert.ToDouble(SqlCmd.ExecuteScalar);
                Res = Convert.ToDouble(SqlCmd.ExecuteScalar());
            }
            else
            {
                SqlCommand Cmd = new SqlCommand(CmdStr, con);

                // returns only 1 value.
                //Res = Convert.ToDouble(Cmd.ExecuteScalar);
                Res = Convert.ToDouble(SqlCmd.ExecuteScalar());
            }

            // close connection.
            con.Close();

            // return double value.
            return Res;

        }
        catch (Exception ex) { }

    }


Syntax is correct but while compileing in enviroment it gives me error
like

ClsDatabase.GetDS(string, string, System.Data.DataSet, System.Data.SqlClient.SqlCommand)': not all code paths return a value


But in VB.NET it works perfect. Am biginner of C#.

Can somebody Help me to resolve the issue.

Thanks in Advance
Yogesh
Posted

1 solution

You need to return something in your catch statement. That's why you are getting an error.
 
Share this answer
 
Comments
YOGESH DHAGE 4-Oct-11 11:49am    
Thanks Buddy It works...... :-)
Mehdi Gholam 4-Oct-11 12:19pm    
Yeep heee!

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