Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7924963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:03:07+00:00 2026-06-03T18:03:07+00:00

So I have a function when fired queries against the database (twice) and returns

  • 0

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.

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.

I then return the dataset.

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.

Please make any suggestions regarding my approach and the issue at hand; I’m always looking to improve!

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 > 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 > 0"
        localDataSet = argHost.GetDataSet(clientSQL)
        If localDataSet.Tables.Count > 0 AndAlso localDataSet.Tables(0).Rows.Count > 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 > 0 AndAlso localDataSet.Tables(0).Rows.Count > 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" & ex.StackTrace & " " & ex.Message)
        Return Nothing
    End Try
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:03:10+00:00Added an answer on June 3, 2026 at 6:03 pm

    Column names must be explicitly stated; for some reason I was thinking the dataset it would implicitly inherit the column names from the imported datarow row.

    clientsWithMonitors.Tables(0).Columns.Add("Foo")
    clientsWithMonitors.Tables(0).Columns.Add("Bar")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function Start() that is fired on ready. When I click on .ExampleClick
If I have function names stored as strings in a Hashtable. Is there a
If I have this window.onresize = function() { alert('resized!!'); }; My function gets fired
I have the following code: $('#button').on('click change', function() { alert('Who fired me, click or
With jquery is it possible to have a function being fired as soon as
I have a function which is fired in Input tag on onClick. The function
Is there a way to have your function be called as the LAST in
I have the following function that executes an query and returns true on success
Is there a function that is fired at the beginning/end of a scenario of
I have some ajax queries that create & manipulate (external) DOM elements during different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.