ASP.Net OOP

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

    #1

    ASP.Net OOP

    OOP Coding
    --------------
    Dim con As New
    SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
    Dim cmd As System.Data.Sql Client.SqlComma nd = New SqlCommand

    Try

    cmd.CommandText = "Insert into TBL_CLAIM_SUMMA RY Select * from
    TBL_MISCELLANEO US"
    cmd.Connection = con
    con.Open()
    cmd.ExecuteNonQ uery()

    Finally

    con.Close()

    End Try

    con.Dispose()
    con = Nothing
    cmd = Nothing

    The above coding is require by page1.aspx,page 2.aspx and page3.aspx and how
    to perform OOP approach?

    Currently I write this coding in every aspx whichever I require but it is
    too difficult to maintain.

    Please advise and please help.


  • Cor Ligthert [MVP]

    #2
    Re: ASP.Net OOP

    Sam,

    This has nothing to do with OOP. In my opinion is your code completely OOP.

    However taking more the in my idea real question of you.

    If you use the VBNet IDE. (Without it is possible however I assume in
    practise impossible).

    Than you can open a "code" page. In that you can use the code that you have
    now made, which makes it more easy to debug. While if you build this code
    than it creates a DLL, which you can place in a separated directory on your
    server. By closing this from the outside, others can by instance not
    download your complete code which is now included in your aspx page and it
    give you a better processing time because it is already precompiled.

    I hope this helps so far. If you have more questions or I did not write it
    in a way that you understand, feel free to reply.

    (That dispose and setting to null is only processing for nothing, it is not
    needed)

    Cor


    Comment

    • CT

      #3
      Re: ASP.Net OOP

      I was going to suggest using a single UserControl that you can place one ach
      of your WebForms, but since there's no UI, that's not the best way to go. I
      think you might want to create either a global method in say a module, or
      you create a shared utility class.

      --
      Carsten Thomsen
      Communities - http://community.integratedsolutions.dk

      "Sam" <samuellai@ajik l.com.my> wrote in message
      news:eFd4rrU0FH A.2064@TK2MSFTN GP09.phx.gbl...[color=blue]
      > OOP Coding
      > --------------
      > Dim con As New
      > SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
      > Dim cmd As System.Data.Sql Client.SqlComma nd = New SqlCommand
      >
      > Try
      >
      > cmd.CommandText = "Insert into TBL_CLAIM_SUMMA RY Select * from
      > TBL_MISCELLANEO US"
      > cmd.Connection = con
      > con.Open()
      > cmd.ExecuteNonQ uery()
      >
      > Finally
      >
      > con.Close()
      >
      > End Try
      >
      > con.Dispose()
      > con = Nothing
      > cmd = Nothing
      >
      > The above coding is require by page1.aspx,page 2.aspx and page3.aspx and
      > how
      > to perform OOP approach?
      >
      > Currently I write this coding in every aspx whichever I require but it is
      > too difficult to maintain.
      >
      > Please advise and please help.
      >
      >[/color]


      Comment

      • m.posseth

        #4
        Re: ASP.Net OOP


        i use a global ( singleton ) data class wich has methods that return the
        data to the closes way i want my data in my process pages
        ( datasets , datatables , string , array`s etc )

        another big advantage is that you can easily implement data caching this way
        ( for data that is used on more as one page for instance)

        ofcourse are all the methods still challenge response methods to my data
        tier ( as this is the only right aproach in ASP like programs )
        ( set connection retrieve the data close the connection )

        regards

        Michel Posseth


        "CT" <carstent@spamm ersgoawayintegr asol.dk> schreef in bericht
        news:u0NMK1V0FH A.2924@TK2MSFTN GP15.phx.gbl...[color=blue]
        >I was going to suggest using a single UserControl that you can place one
        >ach of your WebForms, but since there's no UI, that's not the best way to
        >go. I think you might want to create either a global method in say a
        >module, or you create a shared utility class.
        >
        > --
        > Carsten Thomsen
        > Communities - http://community.integratedsolutions.dk
        >
        > "Sam" <samuellai@ajik l.com.my> wrote in message
        > news:eFd4rrU0FH A.2064@TK2MSFTN GP09.phx.gbl...[color=green]
        >> OOP Coding
        >> --------------
        >> Dim con As New
        >> SqlConnection(C onfigurationSet tings.AppSettin gs("ConnectionS tring"))
        >> Dim cmd As System.Data.Sql Client.SqlComma nd = New SqlCommand
        >>
        >> Try
        >>
        >> cmd.CommandText = "Insert into TBL_CLAIM_SUMMA RY Select * from
        >> TBL_MISCELLANEO US"
        >> cmd.Connection = con
        >> con.Open()
        >> cmd.ExecuteNonQ uery()
        >>
        >> Finally
        >>
        >> con.Close()
        >>
        >> End Try
        >>
        >> con.Dispose()
        >> con = Nothing
        >> cmd = Nothing
        >>
        >> The above coding is require by page1.aspx,page 2.aspx and page3.aspx and
        >> how
        >> to perform OOP approach?
        >>
        >> Currently I write this coding in every aspx whichever I require but it is
        >> too difficult to maintain.
        >>
        >> Please advise and please help.
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Cor Ligthert [MVP]

          #5
          Re: ASP.Net OOP

          Sam,

          If I understood your question wrong as I see from other answers. An approach

          \\\
          Public Class WebsiteDefaults
          Friend Shared Conn As SqlClient.SqlCo nnection
          Friend Shared Sub SetConn()
          Dim connString As String = "The ConnectionStrin g"
          Conn = New SqlClient.SqlCo nnection(connSt ring)
          End Sub
          End Class
          ///

          And than use that as
          websitedefaults .Conn.Open
          websitedefaults .Conn.Close

          Be aware that you can only put things in a shared class that belongs to all
          users in ASPX

          In that class can be more however to give you the example.

          I hope this helps,

          Cor


          Comment

          Working...