views:

53

answers:

2

I have 2 databases. In first one I have 10 tables. Second one is only 1 table. I would like to select 1 columns from each table from 1st database and Insert INTO another database. How can I manage this using INSERT INTO statement in VB.net?

A: 

I hope this helps:

From sql side, you'll just need to write a stored procedure to insert into (ten) hash tables and select/insert them into your target table.

In Vb.net, you'll need: a connection object and a command object to call your stored procedure

Carnotaurus
+1  A: 

I deleted my previous answer saying that you have to manually copy over the data. For now, let's assume you want to do this with a SELECT INTO statement.

The following code shows you how to execute a SQL command on your database using a ADO.NET connection and command object:

' Open a connection to your database (e.g. in a SQL Server): '
Using connection As IDbConnection = New SqlConnection("<Connection string>")
    connection.Open()
    Try

        ' Define the SQL command to be executed here: '
        Dim command As IDbCommand = connection.CreateCommand()
        command.CommandText = "SELECT <...> INTO <...>"

        ' Execute the command: '
        command.ExecuteNonQuery()

    Finally
        connection.Close()
    End Try
End Using
stakx