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?
2 Answers
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
SELECTwith anINSERT INTOstatement. Is it that you want to transfer one row of data from the first database to one table in the second database?SELECT INTO! Question upvoted (and my answer deleted) for teaching me something basic that has somehow eluded me until now.