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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:18:58+00:00 2026-05-24T23:18:58+00:00

I am trying to update a table across non-linked SQL servers using: C# or

  • 0

I am trying to update a table across “non-linked” SQL servers using:
C# or VB.net and ADO.net SqlDataAdapter.

I need to use DataTable and SqlDataAdapter.

Very Important: I need to use BatchUpdate and avoid looping through the DataTable.

The table designs in Server 1 differ from table design in Server 2.

Source Table:

Server 1. Table 1
ID INT
NAME Varchar(30)
Date DateTime

Destination Table:

Server 2. Table 2
ID INT
TableOneId INT (Foreign Key from Server 1. Table 1)
NAME Varchar(30)
Date DateTime

I need a sample on how to update table 2 on server 2 using SqlDataAdapter, or an alternative batch method.

  • 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-24T23:18:59+00:00Added an answer on May 24, 2026 at 11:18 pm

    You should set the UpdateBatchSize property of the SqlDataAdapter to 0 (unlimited).
    I don’t see a way to update table2 without looping table1.

    Here is a sample code to show you one way to achieve this:

    Public Sub BatchUpdate(ByVal table1 As DataTable)
        Dim connectionStringServer2 As String = GetConnectionString()
    
        Using connection As New SqlConnection(connectionStringServer2)
            Dim adapter As New SqlDataAdapter()
    
            'Set the UPDATE command and parameters'
            adapter.UpdateCommand = New SqlCommand( _
              "UPDATE Table2 SET " _
              & "NAME=@NAME,Date=@Date  WHERE TableOneId=@TableOneId;", _
              connection)
            adapter.UpdateCommand.Parameters.Add("@Name", _
              SqlDbType.NVarChar, 50, "Name")
            adapter.UpdateCommand.Parameters.Add("@Date", _
              SqlDbType.DateTime, 0, "Date")
            adapter.UpdateCommand.Parameters.Add("@TableOneId", _
            SqlDbType.Int, 0, "TableOneId")
            adapter.UpdateCommand.UpdatedRowSource = _
              UpdateRowSource.None
    
            ' Set the batch size,' 
            ' try to update all rows in a single round-trip to the server'
            adapter.UpdateBatchSize = 0
    
            Dim table2 As New DataTable("table2")
            table2.Columns.Add(New DataColumn("Name", GetType(String)))
            table2.Columns.Add(New DataColumn("Date", GetType(Date)))
            table2.Columns.Add(New DataColumn("TableOneId", GetType(Int32)))
    
            ' copy content from table1 to table2'
            For Each row As DataRow In table1.Rows
                Dim newRow = table2.NewRow
                newRow("TableOneId") = row("ID")
                newRow("Name") = row("Name")
                newRow("Date") = row("Date")
                table2.Rows.Add(newRow)    
                ' note: i have not tested following, but it might work or give you a clue'
                newRow.AcceptChanges()
                newRow.SetModified()
            Next
            ' Execute the update'
            adapter.Update(table2)
        End Using
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying update my table from c# ado.net with this function.I am using
I'm trying to create an SQL query in PHP to update a table. Is
Hi I am having a problem when trying to update a table using an
I'm trying to update a table via a stored procedure from asp.net. I get
I am trying to update a field using UPDATE table set field='some_variable' where id=1;
I am trying to update thable with select using limit It's update table fine
I am trying to update table A with data from table B. I thought
I'm trying to update one table based on values in another table. What's wrong
I am trying to update a column in my table which was last inserted.
I am trying to update a field in a table with data from another

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.