Losing database connections with dropdown menus

Posted on 2007-10-01
Last Modified: 2013-11-26
I created an 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!
Question by:redouard
    LVL 14

    Expert Comment

    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 Comment

    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
    LVL 14

    Expert Comment

    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 Comment

    Yes that's what I'm doing. Make sense?
    LVL 14

    Accepted Solution

    Seems to me that what you need to do is have 2 seperate statements for loading your drop-down menus.

    You will have to do use the Page.IsPostBack statement

    If Page.IsPostBack then               'something on the page has caused a postback

    '********************RELOAD #2 and #3 here********************

    '** do a Request.Form("Name Of Dropdown") each dropdown that has been re-filled and set that value in the dropdown********

    else                                               ' first time load    
    ' ******************** DO INITIAL LOAD HERE**************
    end if

    Try that and let me know how it goes.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now