|
-
May 26th, 2010, 03:32 PM
#1
Thread Starter
Member
Text values missing from DataTable
I'm having a hard time figuring out why my code will not produce a datatable with text. Can anyone give me a clue, what am I missing? Thanks in advance.
VB Code:
For Each line In Values
' Create rows collection using TableRow object to dynamically add rows
Dim tRow As New TableRow()
' Split the current line in the Values list
Dim split As String() = line.Split(New [Char]() {})
' Assign the values from the split(0...5)
Dim sb_Text As String = ""
Dim sb_CTime As String = ""
' Set Time Zone
Dim sb_TZ As String = "EST"
' Reset the counter to 0 for each line
Dim evaluated As Int32 = 0
Dim sl As New LiteralControl
' Loop through the split string array to get the values assigned to the elements
' passed to the TableCell object, should always be 6 elements/columns
For Each s As String In split
' Create a new cell fro the current row
Dim tCell As New TableCell()
Dim dRow As DataRow
dRow = dt.NewRow()
' If the current s value contains pdf or txt, s is the Text value
If s.Contains("pdf") Or s.Contains("txt") Then
sb_Text = "<a href=""" + RepURLPath + s + """>" + s + "</a>"
evaluated = evaluated + 1
' Create a Hyperlink Web Server control and add to cell
Dim h As New HyperLink()
h.Text = s
h.NavigateUrl = sb_Text
' Add cell to row
h = h
'tCell.Controls.Add(h)
'tCell.Text = h.Text
dRow("File") = h
' If s contains :, it must be the CTime value
ElseIf s.Contains(":") Then
sb_CTime = s
evaluated = evaluated + 1
' Used instr to find first colon, advance to milliseconds, then remove milliseconds
' from the second colon on
Dim colfind = InStr(":", sb_CTime)
sb_CTime = sb_CTime.Remove(colfind + 4, 3)
' Convert string to string literal control
'sl.Text = sb_CTime
'tCell.Controls.Add(sl)
'tCell.Text = sl.Text
dRow("Time") = sb_CTime
' If s contains AM or PM, it must be Ampm value
ElseIf s.Contains("AM") Or s.Contains("PM") Then
evaluated = evaluated + 1
' Convert string to string literal control
'sl.Text = s
'tCell.Controls.Add(sl)
'tCell.Text = sl.Text
dRow("AM/PM") = s
' If s contains / , it must be the modified/lastwrite value
ElseIf s.Contains("/") Then
evaluated = evaluated + 1
' Convert string to string literal control
'sl.Text = s
'tCell.Controls.Add(sl)
'tCell.Text = sl.Text
dRow("Date") = s
' Else s does not contain does not contain the punctuation marks
' : < and / , it must be the fsize value+
Else
evaluated = evaluated + 1
' Convert string to string literal control
'sl.Text = s
'tCell.Controls.Add(sl)
'tCell.Text = sl.Text
dRow("Size") = s
End If
' If evaluated is equal to 5, (0...4), all seperate elements of the single
' value s have been evaluated. Output the lines into the formated columns
' changed to 5 from 6 because the <BR> was removed
If evaluated = 5 Then
' Add time zone cell to row
dRow("Zone") = sb_TZ
' Add new table cells object to the row
tRow.Cells.Add(tCell)
End If
Next
' Add cell collection/row to table once all values for the current line is evaluated
dt.Rows.Add(tRow)
Next
-
May 26th, 2010, 04:02 PM
#2
Re: Text values missing from DataTable
It looks like the ELSE part of the IF block is the culprit. Have you tried putting a breakpoint there and debug the code?
-
May 27th, 2010, 08:49 AM
#3
Thread Starter
Member
Re: Text values missing from DataTable
Yes, I used breakpoints while debugging and couldn't find the problem. The varable s is getting each value from splitting the string. The Else IF block doesn't seem to be the issue. The code was originally using a stringbuilder to output to a label control so I'm certain the decision blocks work. I must use a DataTable instead to display data in the browser now. The table and cells get created, but only the first "File" column has content showing System.Web.UI.WebControls.TableRow. How do I show the actual values in all cells? Thanks for your help.
-
May 27th, 2010, 11:39 AM
#4
Re: Text values missing from DataTable
Can more than one condition be true?
I think what you need is If..EndIf blocks, instead of If..ElseIf blocks.
Code:
If s.Contains("pdf") Or s.Contains("txt") Then
...
End If
If s.Contains(":") Then
...
End If
.
.
.
-
May 27th, 2010, 01:01 PM
#5
Thread Starter
Member
Re: Text values missing from DataTable
All code blocks are being evaluated with the If ElseIf blocks. However, I did revamp the code to use If EndIf code blocks as suggested. It produces the same result.
-
May 28th, 2010, 01:03 PM
#6
Thread Starter
Member
Re: Text values missing from DataTable
Help, I have been Googling for an answer for days. This may be a simple problem that I'm failing to recognize. Any help is appreciated. Thanks.
-
May 29th, 2010, 05:59 AM
#7
Re: Text values missing from DataTable
Put a breakpoint on dt.Rows.Add(tRow) and then check the value of each column whenever it breaks. Do you have all the values there?
Also I suspect this line is causing the problems.
Code:
Dim split As String() = line.Split(New [Char]() {})
On what character do you want to split the string?
Try replacing it with this line and see if it works:
vb Code:
Dim split() As String = Strings.Split(line, ";") '<-- replace semicolon with your separator character.
-
Jun 3rd, 2010, 09:58 AM
#8
Thread Starter
Member
Re: Text values missing from DataTable
I tried modifying the split procedure as you suggested and it didnt' produce any positive results. I'm splitting the s string by whitespace between the char elements then assigning them to individual string variables. It seems the problem lies between assigning the variables to the gridview or how the datasource is identified. From searching the web and reviewing books, there aren't many examples on how to assign arraylist to gridviews. Do you have a recommendation? Once again, thanks for your help.
-
Jun 3rd, 2010, 10:16 AM
#9
Re: Text values missing from DataTable
What happens if put a breakpoint on that point and proceed line by line. How many splits do you get?
-
Jun 3rd, 2010, 10:44 AM
#10
Thread Starter
Member
Re: Text values missing from DataTable
The split pulls all five elements from the string as expected. I just stepped through the code again to varify.
-
Jun 3rd, 2010, 12:52 PM
#11
Re: Text values missing from DataTable
So where does it go missing? Have you tried continue debugging that line onwards line by line for a full one record?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|