?
Solved

Losing database connections with dropdown menus

Posted on 2007-10-01
5
Medium Priority
?
213 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!
0
Comment
Question by:redouard
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:NBSO_ISS
ID: 19992118
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.
0
 

Author Comment

by:redouard
ID: 19992187
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
0
 
LVL 14

Expert Comment

by:NBSO_ISS
ID: 19992226
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?



0
 

Author Comment

by:redouard
ID: 19992236
Yes that's what I'm doing. Make sense?
0
 
LVL 14

Accepted Solution

by:
NBSO_ISS earned 375 total points
ID: 19992280
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.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 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