We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


implementing 1-N association

emrahtufan asked
Medium Priority
Last Modified: 2012-08-14
I want to recore samo data in database table. Let me say the name of the table as Educaton. Table Educatin has a 1-N relationship with the table Person. To do this, I have create two class as follows.

public Class Person
    //I have create the association as collections
    public System.Collection.ArrayList myEducation=new ArrayList();
    private int educationPointer=0;

    //I have created a method that is used for populating the data list
    public addEducation( Education me)
          myEducation.add (me)

Public Class Education
   //I have a method to save all the Education Information
    public System.Boolean Save()
         //In this method I have called the some method to execute the necessary sql string

For both classes, I have coded the properties and variables but I do not write them here.

My problem is like that;
From now on What should be the coding strategy in order to implement the 1-n association between the Education and Person Class and save the Education information to the database.

Many thanks
Watch Question

I think you mean 1 to n for Person to Education rather than what you aid above. You should have a Save on the Person not the Education Class.

You would open a transaction and save the person. You would then loop through all the eduction classes and save their details relating to the person. If anything fails then you rollback the transaction, otherwise you commit e.g.

Public Class Person

    Public Sub Save()

            Dim conn As New SqlConnection

            'do person insert getting back person identifier
            Dim personId as Integer = insertCommand.Execute

            for each e as Eduction in myEducation
                'do the education insert


        catch ex as Exception

    End Sub

End Class


Thanks for your response culshaja
Yes you're right.  I mean one person and many education related with the person.
Your code seems good but actually my user interface application composed of succesive page.
For example a person log on to the web site and then want to add their education information (high schools, college etc.)
So I have a person record on the database.
Person goes to the  AddEducation page and then save his/her education information by button click. What I want to do exactly is that;
I want to add the education info in the arraylist on de PersonClass and then add the items in the arraylist to the database.

Hope I can explain the situation.


any comment?
What you then need to do is just do the same idea with the loopingthrough the arraylist nested witin a transaction. In this case you will alredy have the person Id so you don't need to add it again.

james :-)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


many thanks james:)
one more question.
in asp.net environment,
how can I fill the array list.
I mean each time I click the button on the asp.net page, the class person is called and the array is created again and again so I cannot make the array persistent on the memory.
How can I achive the problem?
Many many thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.