Пример #1
0
        public bool tambahBuku(Buku B)
        {
            try
            {
                string query = @"INSERT INTO TBL_BUKU(judul, pengarang, penerbit, tahun, id_kategori)
                    VALUES(@judul, @pengarang, @penerbit, @tahun, @id_kategori)";

                command = new SqlCommand(query, __sqlCon);
                command.Parameters.AddWithValue("@judul", B.Judul);
                command.Parameters.AddWithValue("@pengarang", B.Pengarang);
                command.Parameters.AddWithValue("@penerbit", B.Penerbit);
                command.Parameters.AddWithValue("@tahun", B.Tahun);
                command.Parameters.AddWithValue("@id_kategori", B.Id_kategori);
                __sqlCon.Open();
                command.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                if (__sqlCon.State == ConnectionState.Open)
                {
                    __sqlCon.Close();
                }
            }
        }
Пример #2
0
        public bool ubahBuku(Buku B, int idBuku)
        {
            try
            {
                string query = @"UPDATE TBL_BUKU SET judul = @judul, pengarang = @pengarang, 
                    penerbit = @penerbit, tahun = @tahun, id_kategori = @id_kategori
                    WHERE id_buku = @idbuku";

                command = new SqlCommand(query, __sqlCon);
                command.Parameters.AddWithValue("@judul", B.Judul);
                command.Parameters.AddWithValue("@pengarang", B.Pengarang);
                command.Parameters.AddWithValue("@penerbit", B.Penerbit);
                command.Parameters.AddWithValue("@tahun", B.Tahun);
                command.Parameters.AddWithValue("@id_kategori", B.Id_kategori);
                command.Parameters.AddWithValue("@idbuku", idBuku);
                __sqlCon.Open();
                command.ExecuteNonQuery();
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                if (__sqlCon.State == ConnectionState.Open)
                {
                    __sqlCon.Close();
                }
            }
        }