2012-07-18 78 views
0

dasaset(ds)包含這樣的值comapring兩個數據集,並將數據集中的電話號碼寫入記事本,這不等於dataset1.但是我得到的記事本中的結果就像電話號碼是相等的這兩個數據集通過vb.net比較數據集

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

我試過這樣的,我有你要找的...

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 
結果