Exemplo n.º 1
0
        public bool Delete(categoriaBLL c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myConnstring);

            try
            {
                string sql = "DELETE FROM tbl_categories WHERE id=@id";
                //passando valor usando cmd
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@id", c.id);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 2
0
        public bool Update(categoriaBLL c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myConnstring);

            try
            {
                string sql = "UPDATE tbl_categories SET titlie=@titlie, " +
                             "description=@description, " +
                             "added_date=@added_date, " +
                             "added_by=@added_by " +
                             "WHERE id=@id";


                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@titlie", c.titlie);
                cmd.Parameters.AddWithValue("@description", c.description);
                cmd.Parameters.AddWithValue("@added_date", c.added_date);
                cmd.Parameters.AddWithValue("@added_by", c.added_by);
                cmd.Parameters.AddWithValue("@id", c.id);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Exemplo n.º 3
0
        public bool Insert(categoriaBLL c)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myConnstring);

            try
            {
                string sql = "INSERT INTO tbl_categories(titlie, description, added_date, added_by) " +
                             "VALUES(@titlie, @description, @added_date, @added_by) ";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@titlie", c.titlie);
                cmd.Parameters.AddWithValue("@description", c.description);
                cmd.Parameters.AddWithValue("@added_date", c.added_date);
                cmd.Parameters.AddWithValue("@added_by", c.added_by);


                conn.Open();
                int rows = cmd.ExecuteNonQuery();

                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }