Beispiel #1
0
 public int Delete(Penerbit penerbit)
 {
     strSql = "DELETE FROM penerbit WHERE id = @1";
     using (OleDbCommand cmd = new OleDbCommand(strSql, conn))
     {
         cmd.Parameters.AddWithValue("@1", penerbit.PenerbitID);
         return cmd.ExecuteNonQuery();
     }
 }
Beispiel #2
0
        public int Update(Penerbit penerbit)
        {
            strSql = "UPDATE penerbit SET nama = @1 " +
                     "WHERE id = @2";
            using (OleDbCommand cmd = new OleDbCommand(strSql, conn))
            {
                cmd.Parameters.AddWithValue("@1", penerbit.Nama);
                cmd.Parameters.AddWithValue("@2", penerbit.PenerbitID);

                return cmd.ExecuteNonQuery();
            }
        }
Beispiel #3
0
 private static Penerbit MappingDtrToObject(OleDbDataReader dtr)
 {
     Penerbit penerbit = new Penerbit();
     penerbit.PenerbitID = dtr[0] is DBNull ? 0 : dtr.GetInt32(0);
     penerbit.Nama = dtr[1] is DBNull ? string.Empty : dtr.GetString(1);
     return penerbit;
 }
Beispiel #4
0
        public int Save(Penerbit penerbit)
        {
            strSql = "INSERT INTO penerbit (nama) " +
                     "VALUES (@1)";
            using (OleDbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = strSql;
                cmd.Parameters.AddWithValue("@1", penerbit.Nama);
                cmd.ExecuteNonQuery();

                strSql = "SELECT MAX(id) FROM penerbit";
                cmd.CommandText = strSql;

                // mengembalikan id terakhir penerbit
                return Convert.ToInt32(cmd.ExecuteScalar());
            }
        }