Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
so in my statement I have:

Select first_name from [table1] insert into [table2] (ID, First_name) values (@ID, @first_name)


but if I use the code this way I have to place values into addwithvalue @ID and @first_name.

All I want to do is copy information from one table to the other.

what can I do to remedy this?

What I have tried:

I have been using parameters, but I am not sure that I can do that with this type of statement. I have tried a datareader but it's only giving single values where I need to copy all this and transfer it to another table.
Posted
Updated 12-Sep-17 20:02pm
Comments
PIEBALDconsult 4-Sep-17 12:59pm    
That doesn't look right. Why aren't you doing:
INSERT INTO [table2] (ID, First_name) SELECT ID, First_name FROM [table1]
Member 11856456 4-Sep-17 21:01pm    
I will switch out the statement. I will try it this way, I am running a dual statement because I am getting information from one table into another database and bringing it over to be used in a secondary database

Yes you can !
SQL
SELECT * INTO newtable [IN externaldb]
FROM oldtable
WHERE condition;
 
Share this answer
 
Comments
PIEBALDconsult 4-Sep-17 13:01pm    
That creates a new table.
RickZeeland 4-Sep-17 13:08pm    
Your are right, that might not be what he wants !
Member 11856456 5-Sep-17 10:41am    
I dont mind to create a new table at this point. How would you use the select into if you are using 2 databases? I dont know how to use 2 connection strings and make the work together in vb.net
RickZeeland 5-Sep-17 12:09pm    
If you want to use 2 databases, place the target in [IN externaldb].
I think you can use one connection string for SQL Server, as long as the databases (catalogs) are on the same server, do not specify a 'catalog'.
Member 11856456 5-Sep-17 12:22pm    
could you please give an example as I have not dealt with using 2 databases before. I appreciate the help.
INSERT INTO [table2] (ID, First_name)
SELECT id, first_name FROM [table1]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900