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?
Asked
Active
Viewed 1,302 times
1
-
You cannot `SELECT` with an `INSERT INTO` statement. Is it that you want to transfer one row of data from the first database to one table in the second database? – stakx - no longer contributing Jul 17 '10 at 08:49
-
*\*gasp\**, I didn't actually know about `SELECT INTO`! Question upvoted (and my answer deleted) for teaching me something basic that has somehow eluded me until now. – stakx - no longer contributing Jul 17 '10 at 10:37
-
@stakx, @Carnotaurus Not in vistadb though I think. – Martin Smith Jul 18 '10 at 16:20
2 Answers
2
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 - no longer contributing
- 83,039
- 20
- 168
- 268
0
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

Phil C
- 3,687
- 4
- 29
- 51