Click here to Skip to main content
15,883,807 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I have each panels for each time, the panel shows when u click the time from timeComboBox.

I would like the buttons to be disabled if it is already in the data, for it to be not duplicated.

If the data is already in the *database* or if the seat is reserved i would like the button to be disabled.

Is it possible, where am I supposed to write the code in the book reservation or where the panels are or in the buttons :)

What I have tried:

SqlConnection con = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=LocalDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand cmd = new SqlCommand("SELECT seatNumber FROM CustomersInfo WHERE seatNumber=@seatNumber",con);
            cmd.Parameters.AddWithValue("@seatNumber", textBox1.Text.ToLower());
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                //if the seatNumber already exists.
                button2.Enabled = false;
                button2.BackColor = Color.Red;
            }
            else
            {
                //else
            }
Posted
Comments
[no name] 10-Dec-20 10:54am    
You need a button for every seat on the plan.
Member 15017513 10-Dec-20 20:12pm    
I already have buttons and disabled them but when it's I open the app again it is already enabled. I would like the buttons to be Automaticly Disabled if the seat is already stored in the database, so that it will avoid being duplicated :)
BabyYoda 10-Dec-20 13:58pm    
Looks like you have code to enable the button or not, so what is the question?
Member 15017513 10-Dec-20 20:14pm    
When I open it the buttons are now enabled even if it is already stored in the database. I would like it to be automaticly Disabled if it is already stored in the database, so it will avoid being duplicated :) maybe I would like to check if it is already stored idk should I do that?
DerekT-P 11-Dec-20 4:32am    
"where am I supposed to write the code"? Well, it's entirely up to you and your design. Unless you're really going to give us the entire source for your project (which we wouldn't read anyway), why not ask us the *technical* issue you are struggling with. We don't know if you're stuck with your design, or if you don't know how to disable a button, or you don't understand the event model... hell, we don't even know if you're talking about Winforms, or ASP.Net Webforms, or ASP.Net MVC, or 1001 other things. Would you walk into your (free) doctor's consulting room and say "there's something wrong with me?" because that's about all we've got to go on here...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900