English 中文(简体)
可用独一无二的浏览数据
原标题:datatable to string with unique rows

I have a datatable and I want to create a text file using this datatable. I want that each row of the newly created text file is unique. If there is a duplicate row, then it should add * to both rows ( duplicate rows)

我使用以下法典:

 Dim str As String
            For Each row As DataRow In dataTable.Rows
                str += row(1)    This is text data            
                str += "<br/>"
            Next

请建议我如何使各行各有独一无二之处。

成就

最佳回答

举例来说,我用数据使用一个阵列,但只是用你的可数据替换阵列部分,你应当做得好。 基本上,你编制了一份载有数据可用信息的说明清单,然后使用准则Q来检查和检查数据一度或不止一次。

    Dim data As String() = {"A", "B", "C", "D", "E", "A", "E", "F", "G", "H", "A", "A", "B", "X", "Y", "Z"}
    Dim processedData = New List(Of String)
    Dim rowData = String.Empty
    Dim results = New StringBuilder()

    For Each row As String In data
        processedData.Add(row)
    Next

    For Each row As String In processedData
        rowData = row

        If (processedData.Where(Function(d) d = rowData).Count = 1) Then
            results.Append(rowData)
            results.Append("<br />")
        Else
            results.Append(rowData)
            results.Append("*")
            results.Append("<br />")
        End If

    Next

成果说明

A*<br />
B*<br />
C<br />
D<br />
E*<br />
A*<br />
E*<br />
F<br />
G<br />
H<br />
A*<br />
A*<br />
B*<br />
X<br />
Y<br />
Z<br />
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签