0

dasaset (ds) 包含类似这样的值,将两个数据集合并,并将电话号码从数据集写入记事本,这不等于 dataset1。但是我在记事本中得到结果,就像电话号码一样,这两个数据集都相等

dataset
-------
91  9942321400
91  9865015695
91  9677031515
91  9994828285
91  9688104229

dataset1 values
----------------
91  9942321400
91  9865015695
91  9677031515

expected result in notepad
--------------------------
91  9994828285
91  9688104229

my code
-------
Dim i As Integer = 0
        Dim toggle As Boolean = False
        Do While (i <= ds1.Tables(0).Rows.Count - 1)
            Dim phone As String = ds1.Tables(0).Rows(i).Item(1).ToString
            Dim j As Integer = 0
            Do While (j <= Ds.Tables(0).Rows.Count - 1)
                Dim dumphone As String = Ds.Tables(0).Rows(j).Item(4).ToString
                If dumphone <> phone Then toggle = True 'This will set your flag to add the output.
                j = (j + 1)
            Loop
            'After we're done checking if there's a match, we decided to add it to the output.
            If toggle = True Then

                TextBox1.AppendText(a.ToString & "|" & b.ToString & "|" & c.ToString & "|" & d.ToString & "|" & phone.ToString & "|" & e1.ToString & "|" & f.ToString & "|" & g.ToString & "|" & h.ToString & "|" & i1.ToString & "|" & j1.ToString & "|" & k.ToString & "|" & l.ToString & "|" & m.ToString & "|" & n1.ToString & "|" & o.ToString & "|" & p.ToString & "|" & q.ToString & "|" & r.ToString & "|" & s.ToString & "|" & t.ToString & "|" & u.ToString & "|" & v.ToString & "|" & w.ToString & "|" & x.ToString)
                sw.WriteLine(TextBox1.Text)
                TextBox1.Text = ""
                toggle = False 'Reset the flag for the next value
            End If
            i = (i + 1) 'Move to the next value to check against.
        Loop



but am getting the output in note pad like this
------------------------------------------------
91  9942321400
91  9865015695
91  9677031515
4

1 回答 1

4

我试过这种方式,我得到了你想要的结果......

For i As Integer = 0 To dataset.Tables(0).Rows.Count - 1
            Dim found As Boolean = False
            For j As Integer = 0 To dataset1.Tables(0).Rows.Count - 1
                If dataset.Tables(0).Rows(i)(0).ToString = dataset1.Tables(0).Rows(j)    (0).ToString Then
                    found = True
                End If
            Next
            If found = False Then
                'here you are getting the right result in each loop
                'in this example i'm showing the result in a textbox
                'just change the instruction and write them in your note pad or wherever you want to
                MsgBox(dataset.Tables(0).Rows(i)(0).ToString)
            End If
        Next
于 2012-11-22T18:15:08.927 回答