Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. problem in creating comman connection class

problem in creating comman connection class

Scheduled Pinned Locked Moved ASP.NET
sharepointhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amit Spadez
    wrote on last edited by
    #1

    hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }

    P 2 Replies Last reply
    0
    • A Amit Spadez

      hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      so what is the error in that ?

      A 1 Reply Last reply
      0
      • P Pranay Rana

        so what is the error in that ?

        A Offline
        A Offline
        Amit Spadez
        wrote on last edited by
        #3

        i want to know ..what is the use of inheriting a clsConnection?? for instance, in class "public class registrationDal:clsConnection "

        1 Reply Last reply
        0
        • A Amit Spadez

          hello all, I want to create a common sqlConnection class so that I don't need to create a connection object in every class.. my code is : public class clsConnection { private SqlConnection con = null; public SqlConnection connectionMethod() { using (con = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["cn"])) { if (con.State == ConnectionState.Closed) { con.Open(); return con; } } return con; } public clsConnection() { } } now in another class, I want to inherit the "clsConnection" class like: public class registrationDal:clsConnection { public bool SaveCandidateInfo(string jobTitle) { try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", objCon.connectionMethod()); cmd.CommandType = CommandType.StoredProcedure; } catch {} }

          P Offline
          P Offline
          Pranay Rana
          wrote on last edited by
          #4

          There is no need to inherite class in second fine instead of that you have to create one instance of that class and you have to use that one for ex. public class registrationDal { public bool SaveCandidateInfo(string jobTitle) { clsConnection oclsConnection = new clsConnection (); SqlConnection con = oclsConnection.connectionMethod(); try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", con); cmd.CommandType = CommandType.StoredProcedure; } catch {} }

          A 1 Reply Last reply
          0
          • P Pranay Rana

            There is no need to inherite class in second fine instead of that you have to create one instance of that class and you have to use that one for ex. public class registrationDal { public bool SaveCandidateInfo(string jobTitle) { clsConnection oclsConnection = new clsConnection (); SqlConnection con = oclsConnection.connectionMethod(); try { string encrPwd = Encrypt(this.pwd); SqlCommand cmd = new SqlCommand("sp_candidateinfo", con); cmd.CommandType = CommandType.StoredProcedure; } catch {} }

            A Offline
            A Offline
            Amit Spadez
            wrote on last edited by
            #5

            ok thanx ...but could u tell me the use of inheriting the class in this case???

            P 1 Reply Last reply
            0
            • A Amit Spadez

              ok thanx ...but could u tell me the use of inheriting the class in this case???

              P Offline
              P Offline
              Pranay Rana
              wrote on last edited by
              #6

              hi according to me there is not use to inherit the class over here as per inheritance defination one of the use of inheriatance is to reuse your existance class methods and member

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups