AW.DataAccessLayer.DALHelper.ExecuteScalarSP C# (CSharp) Метод

ExecuteScalarSP() публичный статический Метод

public static ExecuteScalarSP ( string spName, Hashtable spParams ) : Object
spName string
spParams System.Collections.Hashtable
Результат Object
        public static Object ExecuteScalarSP(string spName, Hashtable spParams)
        {
            Object retVal;
            try
            {
                // Open the connection
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    // 1. create a command object identifying
                    // the stored procedure
                    SqlCommand cmd = new SqlCommand(spName, conn);

                    // 2. set the command object so it knows
                    // to execute a stored procedure
                    cmd.CommandType = CommandType.StoredProcedure;

                    // 3. add parameter to command, which
                    // will be passed to the stored procedure
                    foreach (DictionaryEntry spParam in spParams)
                    {
                        cmd.Parameters.Add(new SqlParameter(spParam.Key.ToString(), spParam.Value));
                    }

                    retVal = cmd.ExecuteScalar();

                    return retVal;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }