G
Guest
I'm on a project where the prevoius developer wrote code like below. I
thought stuff like this was bad? Isn't he putting a page into a session
object? And what we are trying to do is hit the db via a Stored Proc to
create a datatable in most cases. This seems like a waste to me. Is this good?
Public Shared Function getSQL(ByRef thePage As Page) As ProjectName.SQLServer
If thePage.Session("mySQLInit") = "1" Then
Return thePage.Session("mySQL")
End If
thePage.Session("mySQL") = New ProjectName.SQLServer
thePage.Session("mySQLInit") = "1"
Return thePage.Session("mySQL")
End Function
And then shoots to the SP to create datatable:
Sub FillDataGrid(ByRef gridData As System.Web.UI.WebControls.DataGrid, ByVal
SQL As String, Optional ByVal bAddNew As Boolean = False)
Dim cnn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings().Item("ConnectionString"))
Dim dt As DataTable = New DataTable("")
Dim dr As DataRow
Dim objDA As SqlClient.SqlDataAdapter
objDA = New SqlClient.SqlDataAdapter
dt = ExecSQLReturnDT(SQL, objDA)
If bAddNew Then
dr = dt.NewRow
dt.Rows.InsertAt(dr, 0)
gridData.EditItemIndex = 0
End If
gridData.DataSource = dt
gridData.DataBind()
End Sub
And I see dozens of this:
page.Page.Session("psedit_PSHistoryID") = ""
thought stuff like this was bad? Isn't he putting a page into a session
object? And what we are trying to do is hit the db via a Stored Proc to
create a datatable in most cases. This seems like a waste to me. Is this good?
Public Shared Function getSQL(ByRef thePage As Page) As ProjectName.SQLServer
If thePage.Session("mySQLInit") = "1" Then
Return thePage.Session("mySQL")
End If
thePage.Session("mySQL") = New ProjectName.SQLServer
thePage.Session("mySQLInit") = "1"
Return thePage.Session("mySQL")
End Function
And then shoots to the SP to create datatable:
Sub FillDataGrid(ByRef gridData As System.Web.UI.WebControls.DataGrid, ByVal
SQL As String, Optional ByVal bAddNew As Boolean = False)
Dim cnn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings().Item("ConnectionString"))
Dim dt As DataTable = New DataTable("")
Dim dr As DataRow
Dim objDA As SqlClient.SqlDataAdapter
objDA = New SqlClient.SqlDataAdapter
dt = ExecSQLReturnDT(SQL, objDA)
If bAddNew Then
dr = dt.NewRow
dt.Rows.InsertAt(dr, 0)
gridData.EditItemIndex = 0
End If
gridData.DataSource = dt
gridData.DataBind()
End Sub
And I see dozens of this:
page.Page.Session("psedit_PSHistoryID") = ""