title: DataSet Row Add / Imports Nothing
body: <p>So I have a function when fired queries against the database (twice) and returns the results in a dataset. It checks the results (to make sure there are some) then loops through and grabs each row from the returned dataset and imports (copies) it to a different dataset.</p>
  
  <p>I also add a primary key into a List so I do not add the same item twice (from the 2nd query) to the dataset.</p>
  
  <p>I then return the dataset.</p>
  
  <p>The problem? The query works and there is a returned value.. however the dataset in which I aim to import the row(s) to does not keep the imported row.</p>
  
  <p>Please make any suggestions regarding my approach and the issue at hand; I'm always looking to improve!</p>
  
  <pre><code>Public Function GetClientsWithMonitors(ByVal argHost As FOO.Interfaces.BAR) As DataSet
      Try
          Dim localDataSet As New DataSet()
          Dim clientsWithMonitors As New DataSet()
          Dim tempList As New List(Of Integer)
  
          clientsWithMonitors.Clear()
          localDataSet.Clear()
          tempList.Clear()
          clientsWithMonitors.Tables.Add()
  
          'SQL getting monitors applied to clients
          Dim clientSQL As String = "SELECT DISTINCT c.ClientID, c.Name FROM agents a LEFT JOIN clients c ON c.ClientID = a.ClientID WHERE a.ClientID &gt; 0"
          'SQL getting monitors applied directly to an agent
          Dim agentSQL As String = "SELECT DISTINCT c.ClientID, c.Name FROM clients c LEFT JOIN computers comp ON c.ClientID = comp.ClientID LEFT JOIN agents a ON comp.ComputerID = a.ComputerID  WHERE a.LocID = 0 AND a.ClientID = 0 AND a.ComputerID &gt; 0"
          localDataSet = argHost.GetDataSet(clientSQL)
          If localDataSet.Tables.Count &gt; 0 AndAlso localDataSet.Tables(0).Rows.Count &gt; 0 Then
              For Each row As DataRow In localDataSet.Tables(0).Rows
                  If Not tempList.Contains(CInt(row("ClientID").ToString())) Then
                      Dim clientID As Integer = CInt(row("ClientID").ToString())
                      clientsWithMonitors.Tables(0).ImportRow(row)
                      tempList.Add(clientID)
                  End If
              Next
          End If
          If localDataSet.Tables.Count &gt; 0 AndAlso localDataSet.Tables(0).Rows.Count &gt; 0 Then
              localDataSet.Clear()
              localDataSet = argHost.GetDataSet(agentSQL)
              For Each row As DataRow In localDataSet.Tables(0).Rows
                  If Not tempList.Contains(CInt(row("ClientID").ToString())) Then
                      Dim clientID As Integer = CInt(row("ClientID").ToString())
                      clientsWithMonitors.Tables(0).ImportRow(row)
                      tempList.Add(clientID)
                  End If
              Next
          End If
          Return clientsWithMonitors
      Catch ex As Exception
          LogEventViaHost(argHost, "Error Getting dataset of clients with a specified monitor" &amp; ex.StackTrace &amp; " " &amp; ex.Message)
          Return Nothing
      End Try
  </code></pre>