473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Database Relationships

I am trying to setup a relationship between 2 tables from an access database but what I have done throws up an error at the part of my code where I set up the relatonship.

Below is my code and my error on line 13 to 15 says - This constraint cannot be enabled as not all values have corresponding parent values.

Any ideas?

Expand|Select|Wrap|Line Numbers
  1.     Public Sub Retrieve()
  2.  
  3.         objDS.Clear()
  4.  
  5.         objCustomerDA.FillSchema(objDS, SchemaType.Source, "CustomerDetails")
  6.  
  7.         objCustomerDA.Fill(objDS, "Customer Details")
  8.  
  9.         objAccountsDA.FillSchema(objDS, SchemaType.Source, "CustomerAccounts")
  10.         objAccountsDA.Fill(objDS, "CustomerAccounts")
  11.  
  12.         objDS.Relations.Clear()
  13.         objDS.Relations.Add("CustomerAccounts2CustomerDetails", _
  14.         objDS.Tables("CustomerDetails").Columns("CustomerID"), _
  15.         objDS.Tables("CustomerAccounts").Columns("CustomerID"))
  16.  
  17.         cboAccounts.Items.Clear()
  18.  
  19.         Dim i As Integer, strCurrentID As String
  20.         For i = 1 To objDS.Tables("CustomerDetails").Rows.Count
  21.             strCurrentID = objDS.Tables("CustomerDetails").Rows(i - 1).Item("CustomerID")
  22.             cboAccounts.Items.Add(strCurrentID)
  23.         Next
  24.  
  25.         cboAccounts.SelectedIndex = 0
  26.  
  27.         FillCustomerDetails()
  28.         FillCustomerAccounts()
  29.  
  30.     End Sub
  31.  
Mar 15 '08 #1
4 1044
I was able to fix that in the end but now have a new problem. My form loads up with all the information appearing in it but no information appears in my list box that uses the relationship between the 2 tables to get the information.

Here is my code for putting the info into the list box. Aswell the program runs with no errors being thrown up but it just doesnt show.

Expand|Select|Wrap|Line Numbers
  1.     Public Sub FillCustomerAccounts()
  2.         Dim objDetails As DataRow
  3.  
  4.  
  5.         lstAccounts.Items.Clear()
  6.  
  7.         objDetails = objDS.Tables("CustomerDetails").Rows.Find( cboAccounts.SelectedItem.ToString)
  8.  
  9.         Dim strAccountsEntry As String
  10.         Dim objAccounts As DataRow
  11.  
  12.         For Each objAccounts In objDetails.GetChildRows("CustomerDetails2CustomerAccounts")
  13.             strAccountsEntry = objAccounts.Item("AccountID") & ", " & _
  14.             objAccounts.Item("AccountNumber") & ", " & objAccounts.Item("AccountType")
  15.             lstAccounts.Items.Add(strAccountsEntry)
  16.  
  17.         Next
  18.     End Sub
  19.  
Mar 15 '08 #2
kenobewan
4,871 Expert 4TB

Expand|Select|Wrap|Line Numbers
  1.     Public Sub FillCustomerAccounts()
  2.         Dim objDetails As DataRow
  3.  
  4.  
  5.         lstAccounts.Items.Clear()
  6.  
  7.         objDetails = objDS.Tables("CustomerDetails").Rows.Find( cboAccounts.SelectedItem.ToString)
  8.  
  9.         Dim strAccountsEntry As String
  10.         Dim objAccounts As DataRow
  11.  
  12.         For Each objAccounts In objDetails.GetChildRows("CustomerDetails2CustomerAccounts")
  13.             strAccountsEntry = objAccounts.Item("AccountID") & ", " & _
  14.             objAccounts.Item("AccountNumber") & ", " & objAccounts.Item("AccountType")
  15.             lstAccounts.Items.Add(strAccountsEntry)
  16.  
  17.         Next
  18.     End Sub
  19.  
You need to bedug the code. If nothing is showing I assume that the listbox is cleared and that the event is working. The next candaidate is strAccountsEntry. Try writing this to see if it has a value. HTH.
Mar 15 '08 #3
You need to bedug the code. If nothing is showing I assume that the listbox is cleared and that the event is working. The next candaidate is strAccountsEntry. Try writing this to see if it has a value. HTH.
it shows up no error when debugged

If i delete all the loop and just equal the listbox to some text it shows the text. when i keep the loop and equal the listbox to some txt it soesnt show anything again. so i think its something to do with the loop.
Mar 15 '08 #4
kenobewan
4,871 Expert 4TB
it shows up no error when debugged

If i delete all the loop and just equal the listbox to some text it shows the text. when i keep the loop and equal the listbox to some txt it soesnt show anything again. so i think its something to do with the loop.
You are referring to VS debugging, I meant developer debugging you have done and isolated the problem to the loop. strAccountsEntry is a prime candidate which is why I suggested writing it value. Either your for each is not running or strAccountsEntry has no value. To find out which use a try catch block around the loop. HTH.
Mar 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Patrick K. O'Brien | last post by:
I'm looking for a good schema to use as an example for an object database system. Something like a books/authors/publishers or teachers/students/courses kind of thing. There are plenty of...
5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
2
by: Marc R. Bertrand | last post by:
Hello, Do some of you know some pretty good books or web tutorials on building databases, if any? By that I mean, when looking at a business, the sound way of choosing the proper fields and the...
11
by: dixie | last post by:
If I wanted to be able to copy all of the tables in an existing database called Original.mde to another database called New.mde from a button click event in Original.mde, is there an easy way of...
3
by: James Armstrong | last post by:
Hi all, (warning - long post ahead) I have been tasked with designing a database for my company which will store trade information (it is a financial firm). It will need to export this info...
5
by: Deano | last post by:
I'm experiencing bloat problems when I restore my backup files. Users can take a look at the reports of any previous backup without having to ensure they have a backup of their current data - this...
5
by: Mike Turco | last post by:
What is the difference between creating relationships in the front-end vs. the back-end database? I was trying to create a relationship in a database front-end and noticed that I could not check...
3
by: teedilo | last post by:
Our MS SQL (SQL Server 2000) DBA has database privileges locked down pretty tightly. We end users/developers do not have administrator privileges for most databases. That arrangement has worked...
4
by: celinesuzzarini | last post by:
Hi all, I have split my database a while ago, and now, I want to add a table with relationships to other existing tables. I open the BE, create my table, and then go to the relationships...
5
by: mark_aok | last post by:
Hi all, I have a situation where I have a split database. At the back end, I need to - create a new table (I will call it newTable) with the exact fields, and relationships as another table...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.