ASP.Net OOP

S

Sam

OOP Coding
--------------
Dim con As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim cmd As System.Data.SqlClient.SqlCommand = New SqlCommand

Try

cmd.CommandText = "Insert into TBL_CLAIM_SUMMARY Select * from
TBL_MISCELLANEOUS"
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()

Finally

con.Close()

End Try

con.Dispose()
con = Nothing
cmd = Nothing

The above coding is require by page1.aspx,page2.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.
 
C

Cor Ligthert [MVP]

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
 
C

CT

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.
 
M

m.posseth

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
 
C

Cor Ligthert [MVP]

Sam,

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

\\\
Public Class WebsiteDefaults
Friend Shared Conn As SqlClient.SqlConnection
Friend Shared Sub SetConn()
Dim connString As String = "The ConnectionString"
Conn = New SqlClient.SqlConnection(connString)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top