1

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?

3
  • 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? Commented Jul 17, 2010 at 8: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. Commented Jul 17, 2010 at 10:37
  • @stakx, @Carnotaurus Not in vistadb though I think. Commented Jul 18, 2010 at 16:20

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.