locked
Iterate Through Dataset RRS feed

  • Question

  • User-1546380551 posted

    Hi,

    I have a table with a few colums and the test data is 500 rows in which I am trying to create a string of 'a' records in a string builder, which is working fine but the number of 'a' records are duplicated more than twice, which doesn't make sense. If I check the number of rows it reads correctly so I am unsure how come these items are duplicated.

    I am just using the usual code anyone would use:

    Dim sb As StringBuilder = New StringBuilder
    Dim strTemp As String = String.Empty
    
    For i As Integer = 0 To ds.Tables(strTable).Rows.Count
        strTemp += "My Code Here To Create The 'a' tag"
    ' URL (href), Link Text (title), Link Text (clickable text)
    strTemp += ds.Tables(strTable).Rows(i).Item(2) bla bla ds.Tables(strTable).Rows(i).Item(1) bla bla ds.Tables(strTable).Rows(i).Item(1) sb.Append(strTemp) Next

    Database Table Colums:

    1) An Integer
    2) Link Text
    3) URL
    4) Not Important

    The StringBuilder outputs the finished string like so: Link 1, Link 1, Link 2, Link 2... Link 1, Link 1, Link 2, Link 2 rather than Link 1, Link 2, Link 3 and so on. That's what doesn't make sense. Why is it duplicating?

    Have searched Google so not interested in links. This is a VB.NET forum so not interested in C#, C++, F# and so on.

    Any ideas?

    Wednesday, June 4, 2014 6:05 PM

Answers

  • User-760709272 posted

    Change

    strTemp += "My Code Here To Create The 'a' tag"

    to

    strTemp = "My Code Here To Create The 'a' tag"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2014 6:15 PM

All replies

  • User-760709272 posted

    Change

    strTemp += "My Code Here To Create The 'a' tag"

    to

    strTemp = "My Code Here To Create The 'a' tag"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 4, 2014 6:15 PM
  • User-1546380551 posted

    I am so shattered I never saw that I still had that in there from something earlier - cheers

    Wednesday, June 4, 2014 6:18 PM