I want this code to work as if [flag==0] then set seatcount to 1 else provide me a message that seat is booked but it does not give me proper response
it works for seatcount==1 & shows meassage that its booked
but for seatcount==0 then also it provide same message
what should be improved so it would work properly
protected void btn1_Click(object sender, EventArgs e)
{
SqlDataReader sdr;
SqlConnection con = new SqlConnection(" server = localhost;database = booking;Integrated Security=SSPI");
con.Open();
string sqlUserName;
sqlUserName = "SELECT seatcount FROM seat where seatid='1'";
SqlCommand cd = new SqlCommand(sqlUserName, con);
//SqlCommand com = new SqlCommand(sqlUserName, Con);
sdr = cd.ExecuteReader();
if (sdr.Read() == false)
{
flag = 1;
if (flag == 1)
{
SqlConnection conn = new SqlConnection(" server = localhost;database = booking;Integrated Security=SSPI");
conn.Open();
string updateString = @"
update seat
set seatcount = '1'
where seatid = '1'";
SqlCommand cmd = new SqlCommand(updateString);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
Response.Write("Record Updated");
}
}
else
Response.Write("Seat is booked");
}