Beispiel #1
0
        public string deleteBarang(string id)
        {
            Koneksi       kon    = new Koneksi();
            SqlConnection sqlcon = kon.getConnection();
            string        msg    = string.Empty;

            using (sqlcon){
                sqlcon.Open();
                string     sql    = "delete from barang where idbarang = @id";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcom){
                    sqlcom.Parameters.AddWithValue("@id", id);
                    int res = sqlcom.ExecuteNonQuery();
                    msg = (res != 0? "Data has been deleted." : "Error !");
                }
                sqlcon.Close();
            }
            return(msg);
        }
Beispiel #2
0
        public string insertBarang(BarangInfo data)
        {
            Koneksi       con    = new Koneksi();
            SqlConnection sqlcon = con.getConnection();
            string        msg    = string.Empty;

            using (sqlcon)
            {
                sqlcon.Open();
                string     sql    = "insert into barang values (@id, @nama, @stok, @harga)";
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                using (sqlcom)
                {
                    sqlcom.Parameters.AddWithValue("@id", data.IDBarang);
                    sqlcom.Parameters.AddWithValue("@nama", data.NamaBarang);
                    sqlcom.Parameters.AddWithValue("@stok", data.StokBarang);
                    sqlcom.Parameters.AddWithValue("@harga", data.HargaBarang);
                    int res = sqlcom.ExecuteNonQuery();
                    msg = (res != 0 ? "Data has been saved." : "Error !");
                }
                sqlcon.Close();
            }
            return(msg);
        }