In my project, the user can book an holiday and when the manager logs into their account, the manager can review the holidays booked by the users.
When the user books their holiday, the holiday information goes to the database I have created. In the database, I have set the primary key to holiday Number instead of the user Id because the user may add 1 or more holidays to the database. Trouble is, the holiday Number is always 0.
Here's my database:
As you can see on the database the holiday number is 0 and when a user books a holiday it will not add to the database because the holiday number is 0.
How would I add to the holiday Number every time a user books an holiday?
e.g.
50 Richard 27/02/15 29/02/15 Not reviewed 0
50 Richard 27/02/15 29/02/15 Not reviewed 1
50 Richard 27/02/15 29/02/15 Not reviewed 2
50 Richard 27/02/15 29/02/15 Not reviewed 3
My code:
string connectionString = con;
using (SqlConnection connection = new SqlConnection(connectionString))
{
int i = 0;
string setAuthorised = "Not reviewed";
SqlCommand cmd = new SqlCommand("INSERT INTO Holidays (Id, Firstname, Datefrom, Dateto, Authorised, HolidayNo) VALUES (@Id, @Firstname, @Datefrom, @Dateto, @Authorised, @HolidayNo)");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@Id", idTb.Text);
cmd.Parameters.AddWithValue("@Firstname", firstNameTb.Text);
cmd.Parameters.AddWithValue("@Datefrom", dateFromTb.Text);
cmd.Parameters.AddWithValue("@Dateto", dateToTb.Text);
cmd.Parameters.AddWithValue("@Authorised", setAuthorised);
cmd.Parameters.AddWithValue("@HolidayNo", i);
.AddWithValue()- it can lead to unexpected and surprising results...