B
BillE
Hi!
I'm transferring the records in a table from one database to another.
I create a data adapter using a connection from the first database to fill a
dataset.
I add an InsertCommand with a different connection to the second database,
and add the necessary parameters.
I hoped that when I called the update method, the records in the dataset
added from the first database would be inserted into the identical table in
the second database.
This didn't work, but no exception was thrown. Just no records were added.
My code is like this modified code from msdn - should this work?
Private Sub AdapterUpdate(ByVal connectionStringA As String, ByVal
connectionStringB As String)
dim connectionA As SqlConnection = New SqlConnection( _
connectionStringA)
dim connectionB As SqlConnection = New SqlConnection( _
connectionStringB)
Dim adapter As SqlDataAdapter = New SqlDataAdapter( _
"SELECT CategoryID, CategoryName FROM dbo.Categories", _
connectionA)
adapter.InsertCommand = New SqlCommand( _
"INSERT Categories (CategoryName) values (@CategoryName),
connectionB)
adapter.UpdateCommand.Parameters.Add( _
"@CategoryName", SqlDbType.NVarChar, 15, "CategoryName")
Dim categoryTable As New DataTable
adapter.Fill(categoryTable)
adapter.Update(categoryTable)
End Sub
I'm transferring the records in a table from one database to another.
I create a data adapter using a connection from the first database to fill a
dataset.
I add an InsertCommand with a different connection to the second database,
and add the necessary parameters.
I hoped that when I called the update method, the records in the dataset
added from the first database would be inserted into the identical table in
the second database.
This didn't work, but no exception was thrown. Just no records were added.
My code is like this modified code from msdn - should this work?
Private Sub AdapterUpdate(ByVal connectionStringA As String, ByVal
connectionStringB As String)
dim connectionA As SqlConnection = New SqlConnection( _
connectionStringA)
dim connectionB As SqlConnection = New SqlConnection( _
connectionStringB)
Dim adapter As SqlDataAdapter = New SqlDataAdapter( _
"SELECT CategoryID, CategoryName FROM dbo.Categories", _
connectionA)
adapter.InsertCommand = New SqlCommand( _
"INSERT Categories (CategoryName) values (@CategoryName),
connectionB)
adapter.UpdateCommand.Parameters.Add( _
"@CategoryName", SqlDbType.NVarChar, 15, "CategoryName")
Dim categoryTable As New DataTable
adapter.Fill(categoryTable)
adapter.Update(categoryTable)
End Sub