Database Relationships

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • javatech007
    New Member
    • Nov 2007
    • 51

    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?

    [CODE=.VBNET]
    Public Sub Retrieve()

    objDS.Clear()

    objCustomerDA.F illSchema(objDS , SchemaType.Sour ce, "CustomerDetail s")

    objCustomerDA.F ill(objDS, "Customer Details")

    objAccountsDA.F illSchema(objDS , SchemaType.Sour ce, "CustomerAccoun ts")
    objAccountsDA.F ill(objDS, "CustomerAccoun ts")

    objDS.Relations .Clear()
    objDS.Relations .Add("CustomerA ccounts2Custome rDetails", _
    objDS.Tables("C ustomerDetails" ).Columns("Cust omerID"), _
    objDS.Tables("C ustomerAccounts ").Columns("Cus tomerID"))

    cboAccounts.Ite ms.Clear()

    Dim i As Integer, strCurrentID As String
    For i = 1 To objDS.Tables("C ustomerDetails" ).Rows.Count
    strCurrentID = objDS.Tables("C ustomerDetails" ).Rows(i - 1).Item("Custom erID")
    cboAccounts.Ite ms.Add(strCurre ntID)
    Next

    cboAccounts.Sel ectedIndex = 0

    FillCustomerDet ails()
    FillCustomerAcc ounts()

    End Sub
    [/CODE]
  • javatech007
    New Member
    • Nov 2007
    • 51

    #2
    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.

    [CODE=vbnet]
    Public Sub FillCustomerAcc ounts()
    Dim objDetails As DataRow


    lstAccounts.Ite ms.Clear()

    objDetails = objDS.Tables("C ustomerDetails" ).Rows.Find( cboAccounts.Sel ectedItem.ToStr ing)

    Dim strAccountsEntr y As String
    Dim objAccounts As DataRow

    For Each objAccounts In objDetails.GetC hildRows("Custo merDetails2Cust omerAccounts")
    strAccountsEntr y = objAccounts.Ite m("AccountID" ) & ", " & _
    objAccounts.Ite m("AccountNumbe r") & ", " & objAccounts.Ite m("AccountType" )
    lstAccounts.Ite ms.Add(strAccou ntsEntry)

    Next
    End Sub
    [/CODE]

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Originally posted by javatech007

      [CODE=vbnet]
      Public Sub FillCustomerAcc ounts()
      Dim objDetails As DataRow


      lstAccounts.Ite ms.Clear()

      objDetails = objDS.Tables("C ustomerDetails" ).Rows.Find( cboAccounts.Sel ectedItem.ToStr ing)

      Dim strAccountsEntr y As String
      Dim objAccounts As DataRow

      For Each objAccounts In objDetails.GetC hildRows("Custo merDetails2Cust omerAccounts")
      strAccountsEntr y = objAccounts.Ite m("AccountID" ) & ", " & _
      objAccounts.Ite m("AccountNumbe r") & ", " & objAccounts.Ite m("AccountType" )
      lstAccounts.Ite ms.Add(strAccou ntsEntry)

      Next
      End Sub
      [/CODE]
      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 strAccountsEntr y. Try writing this to see if it has a value. HTH.

      Comment

      • javatech007
        New Member
        • Nov 2007
        • 51

        #4
        Originally posted by kenobewan
        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 strAccountsEntr y. 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.

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Originally posted by javatech007
          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. strAccountsEntr y is a prime candidate which is why I suggested writing it value. Either your for each is not running or strAccountsEntr y has no value. To find out which use a try catch block around the loop. HTH.

          Comment

          Working...