Ok so this is going to take some explaining.
The process I am trying to do is grab data from a table function in SQL and then fill a dataset with the returned values. I then have to run this query twice more to query an alternative number table. Then add to the same table as the previous queries. This needs to be as fast as possible, so I am currently using an adapter.fill to populate the datasets and then a dataset.merge to put them all into one table.
The problem is the query can return duplicates which waste time and space, because of this I made column 3(part_ID) the primary key to stop duplicates.
When this is run with the .merge it quits at the first instance of a duplication and doesn't continue with the population.
The code below is what I used to fix this, I was just wondering if there is a better more elegant solution.
com = New SqlCommand(sqlPN, myConnect) adapter.SelectCommand = com adapter.Fill(temp, "Table(0)") Dim data As New DataSet data = temp temp.Tables(0).Columns(3).Unique = True firstSet = temp.Tables(0).Rows.Count temp.AcceptChanges() If temp.Tables(0).Rows.Count < maxRecords Then Dim sqlAlt As String = "select Top " & (maxRecords + 10 - temp.Tables(0).Rows.Count) & " * from getAltEnquiry('" & tbSearchFor.Text & "') ORDER BY spn_partnumber" adapter.SelectCommand.CommandText = sqlAlt adapter.FillLoadOption = LoadOption.OverwriteChanges adapter.Fill(temp, "Table(1)") For i = 0 To temp.Tables(1).Rows.Count - 1 Try temp.Tables(0).ImportRow(temp.Tables(1).Rows(i)) Catch e As Exception End Try Next End If If temp.Tables(0).Rows.Count < maxRecords Then Dim sqlSuPN As String = "select Top " & (maxRecords + 5 - temp.Tables(0).Rows.Count) & " * from getSuPNEnquiry('" & tbSearchFor.Text & "') ORDER BY spn_partnumber" adapter.SelectCommand.CommandText = sqlSuPN adapter.Fill(temp, "Table(2)") For i = 0 To temp.Tables(2).Rows.Count - 1 Try temp.Tables(0).ImportRow(temp.Tables(2).Rows(i)) Catch e As Exception End Try Next End If</code>
Thanks for any help or advice ^__^