I want the code for copy data from one sql to another sql (Using C#)
When I click the Button
Copy my db2_connect Database data like:
Code
select * from importdb where bhand = 3 and store = 14To my another database which is: abdConnection
in abdConnection Table is importabd and filed is same (bhand)
Can someone write the complete code.
Thanking You

Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 26, 2014, 3:14 AM EDT
hi,
I think SQL bulk copy feature can help you.
try..
//fill you data set to one server..
DataSet ds = FillData();
//Create connetion for other Server...
SqlConnection sCon = new SqlConnection(@"Other data base connection string");
System.Data.SqlClient.SqlBulkCopy bc = new SqlBulkCopy(sCon);
bc.DestinationTableName = "Destination table Name";
sCon.Open();
bc.WriteToServer(ds.Tables[0]);
bc.Close();
sCon.Close();
hope this will help you.
Junaid Soomro4 reputationPosted Mar 27, 2014, 1:13 AM EDT
error line: SqlDataReader readerr = command.ExecuteReader();
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 27, 2014, 1:27 AM EDT
hi,
I think if you have OLEDB connection so you must have OleDbDataReader.
try
OleDbDataReader readerr = command.ExecuteReader();
same as for odbc connection you must have OdbcDataReader...
hope this will help you.