Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two databases

I want to be able to transfer specific data from one to the other using C#, is there a easy way to transfer a selected record including all related data from one database to another database that has the exact same table schema.

Please keep in mind this also has to pull the relational data ,

I know about insert selects and most probably there's no out-of-box solution for this but has anyone came across a framework I can use ?
Posted
Updated 19-Sep-11 1:33am
v2

Below query transfers all the data from employee table of testsource database
to employee table of testdestination database


SQL
insert into TestDestination.dbo.Employee 
select * from TestSource.dbo.Employee 



for the specific data to transfer you will add where clause for the select as follows
SQL
insert into TestDestination.dbo.Employee 
select * from TestSource.dbo.Employee 
Where Id > 10 and Id < 20
 
Share this answer
 
v2
Comments
AditSheth 19-Sep-11 7:29am    
If Id is Identity then it gives error
sachin10d 19-Sep-11 12:49pm    
specify all the columns name comma separate and eliminate the Identity column
in both insert and select part
sachin10d 19-Sep-11 12:50pm    
insert into TestDestination.dbo.Employee (Column1, Column2, ...)
select (Column1, Column2, ...) from TestSource.dbo.Employee
Where Id > 10 and Id < 20
try the following :

INSERT INTO TargetDB.dbo.TargetTable (ColumnID, SomeColumn1, SomeColumn2)

SELECT ColumnID, SomeColumn1, SomeColumn2

FROM SourceTable
 
Share this answer
 
Hi,

You want to copy data from one table in DB1 to another table in DB2 .
we can do this by using sql command like...solution1

and another one is using c#.

like first retrieve data from one database and then insert that retrieced into another database.


If you clearly specify your table definitions I can easily solve your requirement.

I hope you understood what I said.
 
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