Results 1 to 11 of 11

Thread: Text values missing from DataTable

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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:
    1. For Each line In Values
    2.  
    3.                 ' Create rows collection using TableRow object to dynamically add rows
    4.                 Dim tRow As New TableRow()
    5.  
    6.                 ' Split the current line in the Values list
    7.                 Dim split As String() = line.Split(New [Char]() {})
    8.  
    9.                 ' Assign the values from the split(0...5)
    10.                 Dim sb_Text As String = ""
    11.                 Dim sb_CTime As String = ""
    12.  
    13.                 ' Set Time Zone
    14.                 Dim sb_TZ As String = "EST"
    15.  
    16.                 ' Reset the counter to 0 for each line
    17.                 Dim evaluated As Int32 = 0
    18.  
    19.                 Dim sl As New LiteralControl
    20.  
    21.                 ' Loop through the split string array to get the values assigned to the elements
    22.                 ' passed to the TableCell object, should always be 6 elements/columns
    23.                 For Each s As String In split
    24.  
    25.                     ' Create a new cell fro the current row
    26.                     Dim tCell As New TableCell()
    27.                     Dim dRow As DataRow
    28.                     dRow = dt.NewRow()
    29.  
    30.                     ' If the current s value contains pdf or txt, s is the Text value
    31.                     If s.Contains("pdf") Or s.Contains("txt") Then
    32.                         sb_Text = "<a href=""" + RepURLPath + s + """>" + s + "</a>"
    33.                         evaluated = evaluated + 1
    34.  
    35.                         ' Create a Hyperlink Web Server control and add to cell
    36.                         Dim h As New HyperLink()
    37.                         h.Text = s
    38.                         h.NavigateUrl = sb_Text
    39.  
    40.                         ' Add cell to row
    41.                         h = h
    42.                         'tCell.Controls.Add(h)
    43.                         'tCell.Text = h.Text
    44.                         dRow("File") = h
    45.  
    46.                         ' If s contains :, it must be the CTime value
    47.                     ElseIf s.Contains(":") Then
    48.                         sb_CTime = s
    49.                         evaluated = evaluated + 1
    50.  
    51.                         ' Used instr to find first colon, advance to milliseconds, then remove milliseconds
    52.                         ' from the second colon on
    53.                         Dim colfind = InStr(":", sb_CTime)
    54.                         sb_CTime = sb_CTime.Remove(colfind + 4, 3)
    55.  
    56.                         ' Convert string to string literal control
    57.                         'sl.Text = sb_CTime
    58.                         'tCell.Controls.Add(sl)
    59.                         'tCell.Text = sl.Text
    60.                         dRow("Time") = sb_CTime
    61.  
    62.                         ' If s contains AM or PM, it must be Ampm value
    63.                     ElseIf s.Contains("AM") Or s.Contains("PM") Then
    64.  
    65.                         evaluated = evaluated + 1
    66.  
    67.                         ' Convert string to string literal control
    68.                         'sl.Text = s
    69.                         'tCell.Controls.Add(sl)
    70.                         'tCell.Text = sl.Text
    71.                         dRow("AM/PM") = s
    72.  
    73.                         ' If s contains / , it must be the modified/lastwrite value
    74.                     ElseIf s.Contains("/") Then
    75.  
    76.                         evaluated = evaluated + 1
    77.  
    78.                         ' Convert string to string literal control
    79.                         'sl.Text = s
    80.                         'tCell.Controls.Add(sl)
    81.                         'tCell.Text = sl.Text
    82.                         dRow("Date") = s
    83.  
    84.                         ' Else s does not contain does not contain the punctuation marks
    85.                         ' : < and / , it must be the fsize value+
    86.                     Else
    87.  
    88.                         evaluated = evaluated + 1
    89.  
    90.                         ' Convert string to string literal control
    91.                         'sl.Text = s
    92.                         'tCell.Controls.Add(sl)
    93.                         'tCell.Text = sl.Text
    94.                         dRow("Size") = s
    95.  
    96.                     End If
    97.  
    98.                     ' If evaluated is equal to 5, (0...4), all seperate elements of the single
    99.                     ' value s have been evaluated. Output the lines into the formated columns
    100.                     ' changed to 5 from 6 because the <BR> was removed
    101.                     If evaluated = 5 Then
    102.  
    103.                         ' Add time zone cell to row
    104.                         dRow("Zone") = sb_TZ
    105.  
    106.                         ' Add new table cells object to the row
    107.                         tRow.Cells.Add(tCell)
    108.  
    109.                     End If
    110.                 Next
    111.                 ' Add cell collection/row to table once all values for the current line is evaluated
    112.                 dt.Rows.Add(tRow)
    113.             Next

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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
    .
    .
    .
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  7. #7
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. Dim split() As String = Strings.Split(line, ";") '<-- replace semicolon with your separator character.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  8. #8

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2010
    Location
    DC Metro area
    Posts
    53

    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.

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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
  •  



Click Here to Expand Forum to Full Width