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 7983237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:54:11+00:00 2026-06-04T10:54:11+00:00

I need to marge two datatables with condition. I have a datatable where the

  • 0

I need to marge two datatables with condition. I have a datatable where the data comes from a local XML Database and another datatable where the data comes from a remote SQL Server.

If any update made in the remote datatable I need to update/merge with the local datatable. Here is what I have so far:

Public Sub MargeTwoTable()

    Dim SQL As String = ""
    Dim RemoteTable As New DataTable
    Dim LocalTable As DataTable
    Dim dal As New DalComon
    Dim yy As Integer = 0
    Dim UpdateDate As String
    Dim TableName As String = "V_Book_Price"


    LocalTable = LoadDataTable(TableName, True)
    UpdateDate = LocalTable.Compute("MAX(update_date)", Nothing)


    SQL = "select * from V_Book_Price where Update_Date > '" & UpdateDate & "'"
    RemoteTable = dal.GetDataSetBySQL(SQL).Tables(0)

    If RemoteTable.Rows.Count > 0 Then

        For i = 0 To RemoteTable.Rows.Count - 1
            Dim st As DataRow


            Dim mm() As DataRow = LocalTable.Select("ID = '" & RemoteTable.Rows(i).Item("ID") & "'")

            If mm.Length = 0 Then

                st = LocalTable.NewRow

                For yy = 0 To RemoteTable.Columns.Count - 1
                    st(yy) = RemoteTable.Rows(i)(yy)
                Next

                LocalTable.Rows.Add(st)

            Else
                st = mm(0)

                For yy = 0 To RemoteTable.Columns.Count - 1
                    If IsDate(RemoteTable.Rows(i)(yy)) Then
                        st(yy) = CDate(RemoteTable.Rows(i)(yy)).ToString("s")
                    Else
                        st(yy) = RemoteTable.Rows(i)(yy)
                    End If
                Next

                mm = Nothing
            End If
        Next

    End If

End Sub

In this code data comes from the remote database which updates a date getter then the local database . Both tables have “ID” as the primary key. The code is working well, but the problem is that when more than 1000 records are updated this function takes too long using loops.

  • 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-04T10:54:15+00:00Added an answer on June 4, 2026 at 10:54 am

    Not sure if can be applicable, but have you ever looked at the
    DataTable.LoadDataRow() method?.
    It seems a good candidate to substitute all of you code above.

    Your code could be simplified to these lines

    Dim row as DataRow
    For Each row in RemoteTable.Rows
        LocalTable.LoadDataRow(row.ItemArray, false)
    Next
    

    Another alternative could be the DataTable.Merge that could cut your code to a single line

    LocalTable.Merge(RemoteTable, False)
    

    However, the real effectiveness of these two methods depends on the schema compatibility and from the presence of AutoNumber (identity) columns.

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

Sidebar

Related Questions

I need to compare numeric data from two datatables with the same schema. For
I have two datasets each with one data table pulled from different sources and
I have came across a situation where I need to merge values from two
I need to merge two SELECT statements. There are two tables in my database,
I have two columns in a table. I need to merge these two columns
I think i need a nudge in the right direction: I have two Tobjectlists
I need to merge two tables: Both have a primary key-column date, but with
I have two tab delimited csv files (with headers) that I need to merge
I need to merge two XML documents, overwriting the overlapsed attributes and elements. For
I have two array I need to merge, and using the Union (|) operator

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.