我試圖找到一個Dataset
特定的記錄,這是通過一個查詢的結果填充,例如:如何在DataSet中查找記錄?
Dim ds As New DataSet
Dim query = "SELECT * FROM tax ORDER BY id"
MyAdapter = New MySqlDataAdapter(query, my connection string here)
MyAdapter.Fill(ds)
現在我已經另一個Dataset
與同桌的,但內容另一個數據庫我試圖獲得該字段hash
,這使我可以比較此行hash
的所有字段。其實我所做的就是創建這樣一個循環:
If ds.Tables(0).Rows.Count > 0 Then
Dim x As Integer = 0
For x = 0 To ds.Tables(0).Rows.Count - 1
Dim local_hash = ds.Tables(0).Rows(x).Item("hash")
Dim web_hash = ds2.Tables(0).Rows(x).Item("hash") 'This is another dataset as I explained in the comment above.
If local_hash = web_hash 'compare if the hash is equal
下面這段代碼不會爲一個明顯的原因的工作,這兩個數據庫的索引是在循環不同,那麼我將永遠找不到hash
場指的是數據集上循環的索引。所以我想問問是否有像.Find
這樣的方法或其他可以用來避免這種情況的方法。
您的表中沒有主鍵嗎? –
'發現'由什麼?使用'find'的關鍵是什麼? – Moumit
正如我所說的,我想在名爲ds2的Web數據集中找到字段「hash」。和@AlexB。我有一個PK,但它是一個同步工具,所以我有GUID – Dillinger