Exemplo n.º 1
0
        public StorageAccessLevel GetSQlData(string stringConnection, int _Id)
        {
            //create connection
            SqlConnection conn = new SqlConnection(stringConnection);
            StorageAccessLevel accessLevel = new StorageAccessLevel();
            string sqlGetCmd = @"select Access_Level from AccessLevel where IdAccessLevel = @_IdAccessLevel";
            conn.Open();
            Logger logger = LogManager.GetCurrentClassLogger();
            logger.Info("Inside");
            SqlCommand cmd = new SqlCommand(sqlGetCmd, conn);
            cmd.Parameters.AddWithValue("@_IdAccessLevel", _Id);
            SqlDataReader rdb = cmd.ExecuteReader();
            rdb.Read();
            //begin read value
            accessLevel.IdAccessLevel = _Id;
            accessLevel.Access_Level = (string)GetUnoSQlValue(rdb,"Access_Level");

            if (conn != null)
            {
                conn.Close();
                conn.Dispose();
            }
            else
            {
                logger.Warn("SQlConnection not close");
            }
            if (rdb != null)
            {
                rdb.Close();
                conn.Dispose();
                logger.Info("Method close");
                return accessLevel;
            }
            else
            {
                logger.Warn("Not return element");
                return null;
            }
        }
Exemplo n.º 2
0
        //params object[] values
        //добавление
        public void SetSQlData(string stringConnection, StorageAccessLevel accessLevel)
        {
            SqlConnection conn = new SqlConnection(stringConnection);
            conn.Open();
            Logger logger = LogManager.GetCurrentClassLogger();
            logger.Info("Inside");

            string strInsert = @"insert into AccessLevel(id,first) values (@_Id,@_Access_Level)";
            SqlCommand cmd = new SqlCommand(strInsert, conn);
            cmd.Parameters.AddWithValue("@_Access_Level", accessLevel.Access_Level);
            cmd.ExecuteNonQuery();

            if (conn != null)
            {
                conn.Close();
                conn.Dispose();
            }
            else
            {
                logger.Warn("SQlConnection not close");
            }
        }