0

I have a form in my program that has two drop downs and three buttons. When I run the form, I want the two drop downs to be blank, and one of the buttons to be disabled. I had this setup and working fine, but I have since been working on other classes and forms in the program and, coming back to refine some things, I have found that the code no longer works. The lines in particular are:

private void mainForm_Load(object sender, EventArgs e)
{
    this.roomsTableAdapter.Fill(this.bookingSystemDatabaseDataSet.rooms);
    timeBox.ResetText();
    roomBox.ResetText();
    updateTextOutput();
    bookButton.Enabled = false;
}

The first line uses a TableAdapter to fill the associated 'rooms' drop down box, which works, however the code after this line does not seem to be executed at all. Commenting out the line means that they are executed, but obviously my 'rooms' drop down would be empty. I have tried moving the lines to the main execution point of the form, but the same thing happens.

Furthermore, I have tried to fill the 'rooms' drop down in 'other ways', including:

roomBox.DataSource = roomsTableAdapter.Fill(bookingSystemDatabaseDataSet.rooms);

and:

roomsTableAdapter.Fill(bookingSystemDatabaseDataSet.rooms);
roomBox.DataSource = roomsTableAdapter;

Of course, these attempts are very similar, but I figured I'd give it a shot. As it turns out, the exact same thing happens in each case; the 'roomBox' is filled, then the rest of the code is ignored. Debugging by stepping through backs up what I already thought to be true, the code is not even executed as far as I can tell. There are no errors, and the program runs, so why are these lines being ignored?

the1mike1man
  • 47
  • 1
  • 9
  • Really can't see what's going wrong here. Whilst it's not a massive issue, I'd really appreciate any help you'd have to offer. – the1mike1man Apr 04 '13 at 14:26
  • 1
    Are you **sure** no exceptions are being thrown? See for example http://stackoverflow.com/questions/1583351/silent-failures-in-c-seemingly-unhandled-exceptions-that-does-not-crash-the-pr – sgmoore Apr 04 '13 at 16:50
  • 2
    To follow up from @sgmoore, press (at least in VS2008) Cntl+Alt+E to bring up the handle exceptions. Click the check box for `Common Language Runtime Exceptions` under `Thrown`. – gunr2171 Apr 04 '13 at 16:52
  • @gunr2171 Okay, you guys were spot on. The line that the execution seems to stop for throws an exception: "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." I will look into this error. – the1mike1man Apr 04 '13 at 16:57
  • And...it's fixed. Thanks a ton guys, I really appreciate the help. I will self-answer this in your names. – the1mike1man Apr 04 '13 at 17:01

1 Answers1

1

Whilst the code appeared to run fine, an exception was actually being thrown - as sgmoore suspected, but it did not cause a break. gunr2171 gave the prognosis:

Press Ctrl+Alt+E to bring up the Exceptions window, then tick the box for Common Language Runtime Exceptions under Thrown. This enabled me to see that an error (Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.) was actually apparent. I resolved this by removing the reference to rooms in the data set and recreating it.

Solved with help from sgmoore and gunr2171.

the1mike1man
  • 47
  • 1
  • 9
  • I would personally suggest that you ALWAYS have this value checked. The less unknown errors the better. – gunr2171 Apr 04 '13 at 17:13