Insert into..select from... tables with different connection strings.

  • Thread starter Thread starter em_rdh
  • Start date Start date
E

em_rdh

Guest
I have two tables from different databases. Rows from table 1 need to be inserted into table 2. How do I code this in vb?

I'm rewriting Access queries in vb.net. This will involve two connection strings and commands. But I cannot figure out how to format the sql. Thanks for your help.


INSERT INTO table2 ( <columnA>, <columnB> )
SELECT table1.columnA, table1.columnB
FROM table1




Using air code, it would be something like this (I think):

Dim strSQL As String = String.Empty
Dim conn1 As New connForTable1
Dim cmd1 As New SqlCommand
Dim conn2 As New connForTable2
Dim cmd2 As New SqlCommand

strSQL = _
"INSERT INTO Table2" & _
"(columnA, columnB) " & _
"SELECT FROM Table1 " & _
"columnA, columnB " & _
"WHERE <condition>"
Try
conn1.table1conn.Open()
cmd1.Connection = conn1.table1conn

conn2.table2conn.Open()
cmd2.Connection = conn2.table2conn


cmd?.CommandText = strSQL

cmd?.ExecuteNonQuery()


But I'm not sure how to finish it because of the different connection strings and commands.

Continue reading...
 
Back
Top