I have 3 tables: Student, Books and Borrows:
- Student (id, name, FK_borrow)
- Books (id, name, nbre_books_available int)
- Borrows (borrow_from, borrow_to, FK_student, FK_books)
I want to insert values into the table Borrows
after checking if the column nbre_books_available
is not 0, and update it.
This my attempt
private void fillborrow()
{
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into borrows Values ('"+dateTimePicker1.Value+"','"+dateTimePicker2.Value+"',"+int.Parse(textBox1.Text)+","+int.Parse(textBox2.Text)+")" ;
cn.Open();
int a = cmd.ExecuteNonQuery();
cn.Close();
if (a == 0)
{
MessageBox.Show("Erreur");
}
else
{
MessageBox.Show("Ajouter avec success");
}
cmd.CommandText = "update books set nbre_current = nbre_current - 1 where CodeO = " + int.Parse(textBox1.Text);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
I don't know how to Add the requete that check if the nbre_books_available column is 0 or not