Help On Object Oriented Programming

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Naren

    #1

    Help On Object Oriented Programming

    Hi,
    i am developing one application,tha t is completely
    object oriented application.the main purpose of this
    applicaiton to completely maintain the database
    operations for the project.
    i created one class for the database connection(sql
    server database).i want to use that database connection
    thorough out all classes in the application,how can i
    assign the database connection to the alll the classes.
    any one can help me with one example.
    the example like this

    public class database
    {
    connection.open ()
    }



    public class employee
    {
    public void insertnewemploy ee()
    {
    //here how can i get that database connection
    }
    }

    Thanks in advance.
    Regards
    Naren.
  • Cobus

    #2
    Re: Help On Object Oriented Programming

    Hi Naren

    Maybe try this:

    Database class:
    ----------------

    public class database
    {
    public SqlConnection myConn;
    public database()
    {
    myConn = new SqlConnection(. .);
    myConn.Open();
    }
    }

    Employee Class
    ----------------

    public class Employee
    {
    public SqlConnection myEmpCon;
    public Employee()
    {
    database myDB = new database();
    myEmpCon = myDB.myConn;
    }

    public void InsertNewEmploy ee()
    {
    //Use myEmpCon here.
    }
    }

    Hope this helps

    Cobus Lombard
    Application Developer
    Mint Net
    South Africa

    "Naren" <nkumar@cedarte chno.com> wrote in message
    news:0b5601c3b3 fa$f05b3150$a40 1280a@phx.gbl.. .[color=blue]
    > Hi,
    > i am developing one application,tha t is completely
    > object oriented application.the main purpose of this
    > applicaiton to completely maintain the database
    > operations for the project.
    > i created one class for the database connection(sql
    > server database).i want to use that database connection
    > thorough out all classes in the application,how can i
    > assign the database connection to the alll the classes.
    > any one can help me with one example.
    > the example like this
    >
    > public class database
    > {
    > connection.open ()
    > }
    >
    >
    >
    > public class employee
    > {
    > public void insertnewemploy ee()
    > {
    > //here how can i get that database connection
    > }
    > }
    >
    > Thanks in advance.
    > Regards
    > Naren.[/color]


    Comment

    • Narendra Kumar

      #3
      Re: Help On Object Oriented Programming

      Hi Cobus,
      Thanks for u r mail.i tested that application.but in employee class, i
      am not getting the connection object.in this i wrote the code.

      in database class
      public class database
      {
      public SqlConnection con
      database.userna me="ass"
      databse.passwor d="asdas"
      database.server ="asdas"
      database.catalo g="cad"
      database.connec t()
      {
      con = new SqlConnection(" user id=;password=;. ..")
      con.open()
      }
      }

      in Employee class
      public class Employee
      {
      public SqlConnection empcon
      public Employee()
      {
      database d = new database()
      //but i am not getting the connection here...the variable is undeclared.
      empcon = d.con;
      }
      }

      after completing this,i used this code in form.
      by using this way i implemented.

      in user interface

      Dim emp As Employee
      Dim db As databse
      db = New database()
      db.Connect("sdf ", "s", "d", "d")
      emp = New Employee
      //but i am not getting the connection status here

      how can i get the connection status.
      Thanks in advance.

      Thanks
      Naren



      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Vijaye Raji

        #4
        Re: Help On Object Oriented Programming

        You got all your class definition messed up. Does this even compile?

        "Narendra Kumar" <nkumar@cedarte chno.com> wrote in message
        news:#eggtBCtDH A.2392@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Hi Cobus,
        > Thanks for u r mail.i tested that application.but in employee class, i
        > am not getting the connection object.in this i wrote the code.
        >
        > in database class
        > public class database
        > {
        > public SqlConnection con
        > database.userna me="ass"
        > databse.passwor d="asdas"
        > database.server ="asdas"
        > database.catalo g="cad"
        > database.connec t()
        > {
        > con = new SqlConnection(" user id=;password=;. ..")
        > con.open()
        > }
        > }
        >
        > in Employee class
        > public class Employee
        > {
        > public SqlConnection empcon
        > public Employee()
        > {
        > database d = new database()
        > //but i am not getting the connection here...the variable is undeclared.
        > empcon = d.con;
        > }
        > }
        >
        > after completing this,i used this code in form.
        > by using this way i implemented.
        >
        > in user interface
        >
        > Dim emp As Employee
        > Dim db As databse
        > db = New database()
        > db.Connect("sdf ", "s", "d", "d")
        > emp = New Employee
        > //but i am not getting the connection status here
        >
        > how can i get the connection status.
        > Thanks in advance.
        >
        > Thanks
        > Naren
        >
        >
        >
        > *** Sent via Developersdex http://www.developersdex.com ***
        > Don't just participate in USENET...get rewarded for it![/color]


        Comment

        • Darin

          #5
          Re: Help On Object Oriented Programming

          Why not create a data layer that can be accessed throughout your app! I
          have created a generic database classes for MSSQL, MySQL which my DALC
          access to comunicate with the datasource. In the DALC (data access layer
          components) I create a base class that reads in the connection string from a
          config file and just have all your DALC inherit from the base class in which
          you can create your connection.

          Good Luck

          "Narendra Kumar" <nkumar@cedarte chno.com> wrote in message
          news:%23eggtBCt DHA.2392@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Hi Cobus,
          > Thanks for u r mail.i tested that application.but in employee class, i
          > am not getting the connection object.in this i wrote the code.
          >
          > in database class
          > public class database
          > {
          > public SqlConnection con
          > database.userna me="ass"
          > databse.passwor d="asdas"
          > database.server ="asdas"
          > database.catalo g="cad"
          > database.connec t()
          > {
          > con = new SqlConnection(" user id=;password=;. ..")
          > con.open()
          > }
          > }
          >
          > in Employee class
          > public class Employee
          > {
          > public SqlConnection empcon
          > public Employee()
          > {
          > database d = new database()
          > //but i am not getting the connection here...the variable is undeclared.
          > empcon = d.con;
          > }
          > }
          >
          > after completing this,i used this code in form.
          > by using this way i implemented.
          >
          > in user interface
          >
          > Dim emp As Employee
          > Dim db As databse
          > db = New database()
          > db.Connect("sdf ", "s", "d", "d")
          > emp = New Employee
          > //but i am not getting the connection status here
          >
          > how can i get the connection status.
          > Thanks in advance.
          >
          > Thanks
          > Naren
          >
          >
          >
          > *** Sent via Developersdex http://www.developersdex.com ***
          > Don't just participate in USENET...get rewarded for it![/color]


          Comment

          Working...