R
rn5a
A VB class file has the following code:
Namespace MyNS
Public Class MyClass
Private sqlConn As New SqlConnection(".....")
Public Function Categorize(ByVal Category As String) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
'more code here
...............
Return sqlReader
End Function
Public Function ViewOrder(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
'more code here
...............
Return sqlReader
End Function
End Class
End Namespace
Using VBC, I successfully created a DLL named MyNS.dll
This is the ASPX code:
<%@ Import Namespace="MyNS" %>
<script runat="server">
Public iUserID As Integer
Public boMyClass As MyClass
Public sqlReader As SqlDataReader
Sub Page_Load(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
Sub MySub1(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
Sub MySub2(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
</script>
As you can see in the ASPX code, the first 3 lines in the 3
sub-routines are exactly identical though the rest of the code in the 3
sub-routines differ vastly from each other.
What I would like to know is the way the same code snippet has been
repeated in the 3 subs - is that good programming practice? If no, can
someone suggest me how do I overcome the repeatative code?
Namespace MyNS
Public Class MyClass
Private sqlConn As New SqlConnection(".....")
Public Function Categorize(ByVal Category As String) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
'more code here
...............
Return sqlReader
End Function
Public Function ViewOrder(ByVal UserID As Integer) As
SqlDataReader
Dim sqlCmd As SqlCommand
Dim sqlReader As SqlDataReader
'more code here
...............
Return sqlReader
End Function
End Class
End Namespace
Using VBC, I successfully created a DLL named MyNS.dll
This is the ASPX code:
<%@ Import Namespace="MyNS" %>
<script runat="server">
Public iUserID As Integer
Public boMyClass As MyClass
Public sqlReader As SqlDataReader
Sub Page_Load(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
Sub MySub1(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
Sub MySub2(obj As Object, ea As EventArgs)
iUserID = Request.Cookies("UserID").Value
boMyClass = New MyClass
sqlReader = boMyClass.ViewOrder(iUserID)
.............
.............
End Sub
</script>
As you can see in the ASPX code, the first 3 lines in the 3
sub-routines are exactly identical though the rest of the code in the 3
sub-routines differ vastly from each other.
What I would like to know is the way the same code snippet has been
repeated in the 3 subs - is that good programming practice? If no, can
someone suggest me how do I overcome the repeatative code?