Results 1 to 6 of 6

Thread: DataRelation & Binding Not Working!!

  1. #1

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71

    Question DataRelation & Binding Not Working!!

    I have created a one to one relation between parent “member” table and a child “Measurements” table, the relation works fine.
    The problem is, the child table displayed in a DataGrid in the upper area of the form, & the bottom area I have some textbox which the data in the DataGrid binded to it, meaning when the user clicks on any row in the DataGrid, details should appear in this textboxs, but this is not happening !!!

    I wonder if I have a coding error, next is the code used:

    myDA.Fill(myDS, "Member")
    myMeasureDA.Fill(myDS, "Measure")

    ‘ Add DataRelation the DataSet
    myDS.Relations.Add("MemMsr", myDS.Tables("Member").Columns("MemberID"), myDS.Tables("Measure").Columns("MemberID"))

    ' cbSelect Member DataSource
    Me.cbSelect.DataSource = myDS.Tables("Member")
    Me.cbSelect.DisplayMember = "MemberID"

    ‘ Bind data in the first window form
    Me.txtMemberName_e.DataBindings.Add("Text", myDS.Tables("Member"), "Name_e")

    Me.dgMeasurements.DataSource = myDS.Tables("Measure")

    ‘ the next line is spoiling my next databinding
    Me.dgMeasurements.SetDataBinding(myDS, "Member.MemMsr")

    ‘ bind the 2nd window form (*** this binding get spoiled ***)
    Me.txtWeight.DataBindings.Add("Text", myDS.Tables("Measure"), "Weight")
    Me.txtHeight.DataBindings.Add("Text", myDS.Tables("Measure"), "Height")

    Any idea where is the problem?

    Thanks for the help
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I couldnt exactly understand what you need, please describe more clearly.
    Anyway considering that you have:
    1- A master table called :Members
    2- A details table called : Measurments
    3- A datarelation object called: MemMsr
    4- A dataset called myDS
    5- A datagrid called:dgMeasurements
    6- Two textboxes called: txtHeight, txtWeight
    Then in order to have the data in the 'Members' table in datagrid and the details of each row in two textboxes then you may:
    1-Bind your datagrid to the master table
    2-Set AllowNavigation property of datagrid to False
    3- Bind Textboxes as follows:
    Me.txtWeight.DataBindings.Add("Text", Me.myDS, "Members.MemMsr.Weight")
    or
    Me.txtWeight.DataBindings.Add("Text", Me.myDS, "Members.MemMsr.Height")

  3. #3

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Lunatic3 thank you for your reply.

    Your understanding is correct till # 6 but....after that, Members data are displayed in a tab form (click to see the image)
    http://www.adsc.net/cms/club0.jpg
    And Measurements data are displayed in the Grid, if I clicked any Grid row the Measurements FULL info will be displayed in the save form under the grid in a texbox (http://www.adsc.net/cms/club1.jpg)

    When I bind the Measurements data to the textbox as follow:
    Me.txtWeight.DataBindings.Add("Text", myDS.Tables("Measure.MemMsr"), "Weight")
    I get a run-time error says "value can't be null", while I don't see any thing null

    Any idea please.
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    From what I gathered you want to select an ID in Personl Tab, then going to the Measurments Tab you have several measurments of each ID and the selecting each of them will show you full details in textboxes in panel below. If that's what you want then do this:
    VB Code:
    1. Me.dgMeasurements.SetDataBinding(myDS, "Member.MemMsr")
    2. Me.txtWeight.DataBindings.Add("Text", myDS,"Members.MemMsr.Wight")

    you have to keep the syntax the same to keep synchronization. By the way MemMsr is a member of Members table (master table) not the child table.

  5. #5

    Thread Starter
    Lively Member adsc's Avatar
    Join Date
    Nov 2002
    Location
    Kuwait
    Posts
    71
    Excellent Lunatic3,

    The mistake I was making is, I was binding to Measure DataSet not to the Relation !!

    Thank you very much Lunatic3, you made my day
    <><><><><><><><><><><><><><><><><><>
    <><> REMEMBER,,,,KNOWLEDGE IS POWER <><>
    <><><><><><><><><><><><><><><><><><>

  6. #6
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    you're most welcome!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width