Beispiel #1
0
        public static object ExecuteScalarSP(string StoreProcName, SqlParameter[] param = null)
        {
            try
            {
                var args = new Hashtable();
                if (param == null)
                {
                    return(DBLibs.ExcuteStoreProcedure_Scalar(StoreProcName, args, Cnn));
                }
                foreach (var p in param)
                {
                    if (p.DbType.ToString() == "DateTime")
                    {
                        var timeValue = DateTime
                                        .ParseExact(p.Value.ToString(), "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)
                                        .ToString("yyyy-MM-dd HH:mm:ss.fff");
                        args.Add(p.ParameterName.Replace("@", ""), timeValue);
                    }
                    else
                    {
                        args.Add(p.ParameterName.Replace("@", ""), p.Value.ToString());
                    }
                }
                return(DBLibs.ExcuteStoreProcedure_Scalar(StoreProcName, args, Cnn));
                //SqlCommand cmd = new SqlCommand(StoreProcName);
                //cmd.Connection = con;
                //if (con.State == ConnectionState.Closed) { con.Open(); }
                //cmd.CommandType = CommandType.StoredProcedure;
                //if (param != null)
                //{
                //    for (int i = 0; i < param.Length; i++)
                //    {
                //        cmd.Parameters.Add(param[i]);
                //    }
                //}
                //return cmd.ExecuteScalar();
            }
            catch (Exception)
            {
                return(null);
            }

            finally
            {
                con.Close();
            }
        }
Beispiel #2
0
        public static object ExecuteScalarSP(string storeProcedure)
        {
            //object result;
            try
            {
                return(DBLibs.ExcuteStoreProcedure_Scalar(storeProcedure, new Hashtable(), Cnn));

                //SqlCommand cmd = new SqlCommand(storeProcedure, con);
                //cmd.Connection = con;
                //if (con.State == ConnectionState.Closed) { con.Open(); }
                //cmd.CommandType = CommandType.StoredProcedure;
                //cmd.CommandText = storeProcedure;
                //result = cmd.ExecuteScalar();
                //return result;
            }
            catch { return(null); }

            finally
            {
                con.Close();
            }
        }