Creating an object model

Last post 05-30-2008 2:47 AM by kaushalparik. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-28-2008 11:15 PM

    • uriorlov
    • Top 50 Contributor
    • Joined on 12-03-2007
    • Wannabe Slacker
    • Points 600

    Creating an object model

    I have a flat table in the database with two colums containing a Car. How an object model can be created to represent this data in a different way? For example if want collection of car objects, what should i need to do? Somebody please help.

    Digging deeper into .Net

    Uri Orlov
    Ukraine
  •  Advertisement

    3 MONTHS FREE & FREE SETUP on ASP.NET 3.5/2.0 Web Hosting! Windows 2008 & 2003 Servers Available, MS SQL 2008/2005, .NET 3.5 SP1, Entity Framework, LINQ, Silverlight 2.0, 30 Day Money Back Guarantee – Click Here!

     
  • 05-29-2008 2:45 AM In reply to

    Re: Creating an object model

    check out the link > http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/model.htm

    i also made a simple basic car class object model

    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using App.Data;

    namespace MyCar
    {
        /// <summary>
        /// Summary description for CarClass
        /// </summary>
        public class CarClass
        {
            int _carID;
            string _make;
            string _model;
            int _year;

            //constructure to declare object instance of CarClass
            public CarClass()
            {
                //
                // TODO: Add constructor logic here
                //
                _carID = 0;
                _make = string.Empty;
                _model = string.Empty;
                _year = 0;
            }

            //parameterize constructor
            public CarClass(int argCarID,string argMake,string argModel,int argYear)
            {
                this._carID = argCarID;
                this._make = argMake;
                this._model = argModel;
                this._year = argYear;
            }

            //properties
            public int carID
            {
                get { return _carID; }
                set { _carID = value; }
            }

            public string make
            {
                get { return _make; }
                set { _make = value; }
            }

            public string model
            {
                get { return _model; }
                set { _model = value; }
            }

            public int year
            {
                get { return _year; }
                set { _year = value; }
            }


            //set the car object
            public CarClass setCarObject(int argCarID,string argMake, string argModel, int argYear)
            {
                return new CarClass(argCarID, argMake, argModel, argYear);
            }

            //get/return single car object
            public CarClass setCarObject(int argCarID)
            {
                SqlDataReader objReader;
                SqlParameter objParam = new SqlParameter("@uspCarID",argCarID);
                CarClass objCarClass=new CarClass();
                objReader = SqlHelper.ExecuteReader(ConfigurationManager.AppSettings["ConnectionString"].ToString(), CommandType.StoredProcedure, "USP_FetchCarDetails",objParam);
                if (objReader != null && objReader.HasRows)
                {
                    objReader.Read();
                    objCarClass= new CarClass(Convert.ToInt32(objReader["CarID"]),
                        Convert.ToString(objReader["Make"]),
                        Convert.ToString(objReader["Model"]),
                        Convert.ToInt32(objReader["Year"]));               
                }
                objReader.Close();
                objParam = null;
                return objCarClass;
            }       
        }
    }

     

     

     

    "I would love to change the world, but they won’t give me the source code"

    KaushaL || BLOG || Profile || SEO Tips
  • 05-29-2008 9:50 AM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 10,057
    • MVP

    Re: Creating an object model

    In addition to Kaushal's reply, also checkout this article on DotNetSlackers:

    http://dotnetslackers.com/articles/csharp/PolymorphismEncapsulation.aspx

     

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 05-29-2008 3:17 PM In reply to

    • uriorlov
    • Top 50 Contributor
    • Joined on 12-03-2007
    • Wannabe Slacker
    • Points 600

    Re: Creating an object model

    Hi Kaushal,

    A thousand thanks for clarifying this with your example and the link. Thanks to sonu also for the link. 

    Digging deeper into .Net

    Uri Orlov
    Ukraine
  • 05-30-2008 2:47 AM In reply to

    Re: Creating an object model

    WC. always here to help./.

    "I would love to change the world, but they won’t give me the source code"

    KaushaL || BLOG || Profile || SEO Tips
Page 1 of 1 (5 items)