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

  • Home
  • SEARCH
  • 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 6337601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:16:54+00:00 2026-05-24T19:16:54+00:00

Ok so this is going to take some explaining. The process I am trying

  • 0

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 ^__^

  • 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-05-24T19:16:55+00:00Added an answer on May 24, 2026 at 7:16 pm

    Since you are looping through the records from the additional queries and using the ImportRow, your code will throw an exception if more than one record with the same value in the primary key field is attempted to be inserted. That is the purpose of a primary key when using in this way. If you want to ensure that your table only has unique records, you will need to ensure that the records are distinct before inserting them by checking the new row’s part_id value against those already in the table. However, your design isn’t necessarily the ideal approach.

    Since you mentioned that this needs to be fast, it will probably be best if you could write a stored procedure to return just the rows you need from all tables and do the Fill into the table once.

    If that’s not possible, you can call adapter.Fill on the same DataTable for each of your data sources. Use the Fill overload that takes just the DataTable to fill and as per the docs, it will merge the data together if more than one record with the same primary key exists. The way you have the Fill method called, it is creating a new DataTable with the name you provide for each time you call Fill. Instead, you want to Fill just one DataTable.

    “You can use the Fill method multiple times on the same DataTable. If a primary key exists, incoming rows are merged with matching rows that already exist. If no primary key exists, incoming rows are appended to the DataTable.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably going to take some heat for this question. But I'd like to
This is driving me crazy. I'm not going to take it anymore. I'm going
This is going to be a little tricky to explain. I'm trying to write
Hey this is going to be one of those dumb questions. I am trying
I would like to take some action when tomcat service is going down. For
I need to take some images from the iPhone / iPad photo library from
This is going to sound like a silly question, but I'm still learning C,
This is going to be the noobist of all noob questions, but what exactly
This is going to be hard to explain but I'll try my best. I
This is going to sound too silly / too basic - sorry about that,

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.