Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should set the <a href="http://msdn.microsoft.com/en-us/library/system.data.common.dbdataadapter.updatebatchsize%28v=VS.100%29.aspx" rel="nofollow">UpdateBatchSize</a> property of the SqlDataAdapter to 0 (unlimited). I don't see a way to update table2 without looping table1.</p> <p>Here is a sample code to show you one way to achieve this:</p> <pre><code>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 " _ &amp; "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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload