user2761515
user2761515

Reputation: 19

Convert Data table into string using string builder

I have a table full of data, I would like to know how i would be able to convert each of the rows in this data Table into a string using String builder. all i want to see on the string is the page name and the status.

|ID | PagenName |  error | Message | Status |
|1  | a         |  1     | tt      | failed |
|2  | a         |  1     | tt      | success|
|3  | a         |  1     | tt      | success|
|4  | a         |  1     | tt      | success|

Upvotes: 0

Views: 1167

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460068

You can use Linq-To-DataSet to select what you need:

var data = From row in table
           Let PagenName = row.Field(Of String)("PagenName")
           Let Status = row.Field(Of String)("Status")
           Select String.Format("PageName: {0} Status: {1}", PagenName, Status)

If you want a single string, for example separated by Environment.NewLine:

Dim result As String = String.Join(Environment.NewLine, data)
Console.Write(result)

I would prefer such code because it's readable.

Upvotes: 2

Related Questions