Click here to Skip to main content
15,884,838 members
Articles / Programming Languages / C#

Getting Started With Object Databases

Rate me:
Please Sign up or sign in to vote.
3.92/5 (9 votes)
13 Jul 2006CPOL5 min read 44.5K   349   33  
A programmatic introduction to object database storage and a short comparison of ODBMS and RDBMS systems
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace oodb_gettingstarted
{
    public partial class frmPerson : Form
    {
        DataLayer m_DataLayer = new DataLayer( "testdb.yap" );

        public frmPerson()
        {
            InitializeComponent();
        }

        private void buttonSave_Click( object sender, EventArgs e )
        {
            Person p        = new Person( this.nameTextBox.Text );
            p.Age           = this.ageTextBox.Text.Length > 0 ? int.Parse( this.ageTextBox.Text ) : 0;
            this.m_DataLayer.Save( p );
            this.AddPerson( p );
            this.nameTextBox.Text = this.ageTextBox.Text = null;
        }

        /// <summary>
        /// Add's a person object to the data grid
        /// </summary>
        /// <param name="p"></param>
        private void AddPerson( Person p )
        {
            int newRow = this.peopleGrid.Rows.Add();

            this.peopleGrid.Rows [newRow].Cells ["PersonName"].Value = p.Name;
            this.peopleGrid.Rows [newRow].Cells ["Age"].Value = p.Age;
        }

        private void frmPersons_Load( object sender, EventArgs e )
        {
            foreach ( Person p in this.m_DataLayer.Get() )
            {
                this.AddPerson( p );
            }
        }

        private void frmPerson_FormClosing( object sender, FormClosingEventArgs e )
        {
            this.m_DataLayer.Close();
        }

        private void buttonFindPerson_Click( object sender, EventArgs e )
        {
            IList<Person> people = this.m_DataLayer.Get( new Person( this.textBoxFind.Text ) );
            //IList<int> rows      = new List<int>();

            foreach ( Person p in people )
            {
                foreach ( DataGridViewRow row in this.peopleGrid.Rows )
                {
                    if ( row.Cells ["PersonName"].Value != null && row.Cells ["PersonName"].Value.Equals( p.Name ) )
                    {
                        row.Selected = row.Cells ["PersonName"].Selected = true;
                    }
                    else
                    {
                        row.Selected = row.Cells ["PersonName"].Selected = false;
                    }
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Carlos J. Muentes is an accomplished software engineer with over 11 years of experience building object oriented Desktop and Web applications using various programming languages and technologies on a number of platforms, with a current focus on C#, Java, and Python. Mr. Muentes is a specialist in C# and .NET technologies, having satisfactorily completed Microsoft developer certification exams, achieving Microsoft Certified Professional status.

Carlos is also heavily involved in HIE and HL7/CDA implementations. With a passion for HIE, he hopes to help transform the world, one electronic patient record at a time.

Comments and Discussions