sql server - Copy data from one table in one database to another table in another database -


may there many dublicates of question. never used ado.net, why have problem sqlcommand 2 connection strings.

i found code copy data 1 table in 1 database table in database.

            sqlcommand command = new sqlcommand("select * db2.dbo.car db1.dbo.automobile", constr);              sqldataadapter adapter = new sqldataadapter(command);             dataset dataset = new dataset();             adapter.fill(dataset);             resultgrid.itemssource = dataset.tables["car"].defaultview; 

i use 2 database , so, should set 2 connecting string every database. should set those?

you dont need 2 connection string. query mentioned in ur code snippet need run on db1 db. constr need point db1 db. query run on db1 , create new table car in db2 db.

note: assumption both db1 , db2 exists on same server , user using have access create table in db2 database.


Comments