コード例 #1
0
        public bool ExecuteNonQueryWithParams(string query, List <SqlParameter> parameters)
        {
            string Function_Name = "ExecuteNonQueryWithParams";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            LogHelper.Debug(CLASS_NAME, Function_Name, string.Format("Query = {0}", query));
            DatabaseSession session       = m_sessionFactory.GetDatabaseSession();
            bool            bLocalSession = false;
            int             recordUpdated = 0;
            bool            boolUpdated   = true;

            try
            {
                if (session != null)
                {
                    if (!session.IsConnectionOpen())
                    {
                        session.OpenConnection();
                        bLocalSession = true;
                    }
                    IDbCommand cmd = session.CreateCommand();
                    //Replace Parameter delimiter based on the type
                    query           = session.ReplaceParamelimiterString(query);
                    cmd.CommandText = query;
                    foreach (var item in parameters)
                    {
                        IDbDataParameter parameter = cmd.CreateParameter();
                        parameter.ParameterName = item.ParameterName;
                        parameter.DbType        = item.DbType;
                        parameter.Direction     = item.Direction;
                        parameter.Value         = item.Value;
                        cmd.Parameters.Add(parameter);
                        //cmd.Parameters.Add(item);
                    }
                    recordUpdated = cmd.ExecuteNonQuery();
                    boolUpdated   = false;
                }
            }
            catch (Exception localException)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
            }

            if (bLocalSession)
            {
                session.CloseConnection();
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");

//             if (recordUpdated <= 0)
//             {
//                 return false;
//             }
            return(!boolUpdated);
        }
コード例 #2
0
        public IDataReader ExecuteQueryWithParams(string query, List <SqlParameter> parameters)
        {
            string Function_Name = "ExecuteQueryWithParams";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            LogHelper.Debug(CLASS_NAME, Function_Name, string.Format("Query = {0}", query));

            DatabaseSession session       = m_sessionFactory.GetDatabaseSession();
            bool            bLocalSession = false;
            IDataReader     dr            = null;

            try
            {
                if (session != null)
                {
                    if (!session.IsConnectionOpen())
                    {
                        session.OpenConnection();
                        bLocalSession = true;
                    }
                    query = session.ReplaceParamelimiterString(query);
                    IDbCommand cmd = session.CreateCommand();
                    cmd.CommandText = query;
                    foreach (var item in parameters)
                    {
                        IDbDataParameter parameter = cmd.CreateParameter();
                        parameter.ParameterName = item.ParameterName;
                        parameter.DbType        = item.DbType;
                        parameter.Direction     = item.Direction;
                        parameter.Value         = item.Value;
                        cmd.Parameters.Add(parameter);
                        //cmd.Parameters.Add(item);
                    }
                    dr = cmd.ExecuteReader();


                    //LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
                    //return dr;
                }
            }
            catch (Exception localException)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
            }


            /*if (bLocalSession)
             * {
             *  session.CloseConnection();
             * }*/

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(dr);
        }