Hi All
I am getting above error when I am trying to build the project.Could anyone help me out ?
Error:
'NCCDAL.clsDataAccessLayer.fncreateCmdObj(string, System.Data.SqlClient.SqlParameter[], System.Data.SqlClient.SqlTransaction)': not all code paths return a value'
Code:
public static SqlCommand fncreateCmdObj(string spName ,SqlParameter[] commandParameters,SqlTransaction transaction)
{
SqlCommand command ;
try
{
command = new SqlCommand();
//if we were provided a transaction, assign it and Make Connection .
//Else associate the connection with the command
SqlConnection mObjSqlCn = new SqlConnection();
if (mObjSqlCn.State != ConnectionState.Open)
{
mObjSqlCn.Open();
}
if (transaction != null)
{
command.Transaction = transaction;
command.Connection = transaction.Connection ;
}
else
{
command.Connection = mObjSqlCn ;
}
//set the command text (stored procedure name or SQL statement)
command.CommandText = spName;
//set the command type
command.CommandType = CommandType.StoredProcedure;
//attach the command parameters if they are provided
if (commandParameters != null)
{
foreach (SqlParameter p in commandParameters)
{
//check for derived output value with no value assigned
if ((p.Direction == ParameterDirection.InputOutput) && (p.Value == null))
{
p.Value = DBNull.Value;
}
command.Parameters.Add(p);
}
}
return command;
}
catch (Exception ex)
{
Console.Write ("Error in connection : "+ex.Message);
}
finally
{
}
}
Thank you
Shrikant