Step Right Up, Get Yer Session 'ere
-
Public Sub SomeMethod()
' ...
For Each da As DataRow In myTable.Rows
da(11) = i + 1
items(i) = da(0) & ":" & da(1) & ":NaN:" & da(3) & ":" & da(4) & ":" & da(5) &
":" & da(6) & ":" & da(7) & ":" & da(8) & ":" & da(9) & ":" & da(10) & ":" & da(11) & ":" & da(1)
i += 1
Next
Session("itemTable") = items
'...
End Sub<AjaxMethod()> _
Public Function GetSessionData(ByVal name As String) As Object
Return HttpContext.Current.Session(name)
End FunctionThat is some code I just came across (I took out some stuff and renamed some things to protect the innocent). That basically gets information from a DataTable by index (rather than by field name), puts it into a colon-separated-value string (some of the data items include company names and addresses, which could potentially contain colons) that is stored in an array that gets shoved into the session. There is then some JavaScript that calls the server to get that session data (or any session data a client script feels like grabbing). Luckily, I am replacing this code entirely.
-
Public Sub SomeMethod()
' ...
For Each da As DataRow In myTable.Rows
da(11) = i + 1
items(i) = da(0) & ":" & da(1) & ":NaN:" & da(3) & ":" & da(4) & ":" & da(5) &
":" & da(6) & ":" & da(7) & ":" & da(8) & ":" & da(9) & ":" & da(10) & ":" & da(11) & ":" & da(1)
i += 1
Next
Session("itemTable") = items
'...
End Sub<AjaxMethod()> _
Public Function GetSessionData(ByVal name As String) As Object
Return HttpContext.Current.Session(name)
End FunctionThat is some code I just came across (I took out some stuff and renamed some things to protect the innocent). That basically gets information from a DataTable by index (rather than by field name), puts it into a colon-separated-value string (some of the data items include company names and addresses, which could potentially contain colons) that is stored in an array that gets shoved into the session. There is then some JavaScript that calls the server to get that session data (or any session data a client script feels like grabbing). Luckily, I am replacing this code entirely.
Let me guess. The programmer thought CSV meant "Colon Separated Values". :-D Any reason for "da(1)" to be included twice.
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Public Sub SomeMethod()
' ...
For Each da As DataRow In myTable.Rows
da(11) = i + 1
items(i) = da(0) & ":" & da(1) & ":NaN:" & da(3) & ":" & da(4) & ":" & da(5) &
":" & da(6) & ":" & da(7) & ":" & da(8) & ":" & da(9) & ":" & da(10) & ":" & da(11) & ":" & da(1)
i += 1
Next
Session("itemTable") = items
'...
End Sub<AjaxMethod()> _
Public Function GetSessionData(ByVal name As String) As Object
Return HttpContext.Current.Session(name)
End FunctionThat is some code I just came across (I took out some stuff and renamed some things to protect the innocent). That basically gets information from a DataTable by index (rather than by field name), puts it into a colon-separated-value string (some of the data items include company names and addresses, which could potentially contain colons) that is stored in an array that gets shoved into the session. There is then some JavaScript that calls the server to get that session data (or any session data a client script feels like grabbing). Luckily, I am replacing this code entirely.
AspDotNetDev wrote:
I am replacing this code entirely
Changing or replacing it is easy, but will it be an improvement? :laugh:
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
AspDotNetDev wrote:
I am replacing this code entirely
Changing or replacing it is easy, but will it be an improvement? :laugh:
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Well it doesn't get any worse than the code already is, so there's really only one direction to go. Rapture, here I come!
-
Public Sub SomeMethod()
' ...
For Each da As DataRow In myTable.Rows
da(11) = i + 1
items(i) = da(0) & ":" & da(1) & ":NaN:" & da(3) & ":" & da(4) & ":" & da(5) &
":" & da(6) & ":" & da(7) & ":" & da(8) & ":" & da(9) & ":" & da(10) & ":" & da(11) & ":" & da(1)
i += 1
Next
Session("itemTable") = items
'...
End Sub<AjaxMethod()> _
Public Function GetSessionData(ByVal name As String) As Object
Return HttpContext.Current.Session(name)
End FunctionThat is some code I just came across (I took out some stuff and renamed some things to protect the innocent). That basically gets information from a DataTable by index (rather than by field name), puts it into a colon-separated-value string (some of the data items include company names and addresses, which could potentially contain colons) that is stored in an array that gets shoved into the session. There is then some JavaScript that calls the server to get that session data (or any session data a client script feels like grabbing). Luckily, I am replacing this code entirely.
-
Let me guess. The programmer thought CSV meant "Colon Separated Values". :-D Any reason for "da(1)" to be included twice.
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
-
Public Sub SomeMethod()
' ...
For Each da As DataRow In myTable.Rows
da(11) = i + 1
items(i) = da(0) & ":" & da(1) & ":NaN:" & da(3) & ":" & da(4) & ":" & da(5) &
":" & da(6) & ":" & da(7) & ":" & da(8) & ":" & da(9) & ":" & da(10) & ":" & da(11) & ":" & da(1)
i += 1
Next
Session("itemTable") = items
'...
End Sub<AjaxMethod()> _
Public Function GetSessionData(ByVal name As String) As Object
Return HttpContext.Current.Session(name)
End FunctionThat is some code I just came across (I took out some stuff and renamed some things to protect the innocent). That basically gets information from a DataTable by index (rather than by field name), puts it into a colon-separated-value string (some of the data items include company names and addresses, which could potentially contain colons) that is stored in an array that gets shoved into the session. There is then some JavaScript that calls the server to get that session data (or any session data a client script feels like grabbing). Luckily, I am replacing this code entirely.
I cant overlook that it would have been so much easier to keep the datatable in the session rather than mangle it as a colon csv, there must have been a good reason... then again we see this stuff on DailyWTF.com all the time
-
Yeah, that looks like code that should be replaced. Sadly, I see far too much legacy code that should be replaced. :sigh:
Just because the code works, it doesn't mean that it is good code.
modified on Monday, May 23, 2011 9:18 AM
Isn't that the definition of legacy code?