We help IT Professionals succeed at work.

Losing database connections with dropdown menus

redouard
redouard asked
on
240 Views
Last Modified: 2013-11-26
I created an vb.net aspx page with three dropdown menus. All three dropdown menus are connected to a table in SQL. When the page is load dropdown #1 is populated with two database selections to choose from. Depending on what database you select dropdown #2 and #3 will be populated with different data. The problem, I'm having is when the page is loaded and select an item in dropdown menu #2 or/and #3 and select the submit button, I get an error message like so:

Exception Details: System.Data.SqlClient.SqlException: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'User_FK00'. The conflict occurred in database 'OMNIVISOR_PLUS_HCMB', table 'PatientGroup', column 'PatientGroupID'. Cannot insert the value NULL into column 'UserID', table 'OMNIVISOR_PLUS_HCMB.dbo.Professional'; column does not allow nulls. INSERT fails. The statement has been terminated. The statement has been terminated.

After doing it serveral time, I figured out that when the page is loaded , the items  in the dropdowns are connected to the SQL database. But once I select another items from the dropdowns, I lose connections to the SQL database. How can I prevent this from happening. I attempted to use Page.IsPostBack but it doesn't seem the fix the problem.

Any ideas? Help!
Comment
Watch Question

Commented:
This looks like a completely different issue.  It looks like you are trying to insert a record into a table that is missing the required UserID field.  Unless one of the dropdown contains the UserID, the dropdowns are not likely the problem.

Author

Commented:
I've tested it and can reproduce the problem at will. It seems that when I called the page and select the database, it automatically populate the dropdown menus with the first records in the tables. The insert works at this point. The insert fails when I change the records to another record (or item) selected in the tables from dropdown menus #2 or/and #3.  I think I'm losing the the data bind when another item is selected after the initial page load

Commented:
OK, I see.

So what you are doing is loading the drop downs on initial load of the page and re-loading #2 and #3 when something changes in #1 or #2.  Is this correct?



Author

Commented:
Yes that's what I'm doing. Make sense?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.