Below code sample is how to copy bulk data from one table to another in sqlServer from ASP.NET (C#)
//Create SqlBulkCopy Object
//Code to copy Data from Source to Destination
//Create SqlBulkCopy Object
SqlBulkCopy sbc = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString());
//Code to copy Data from Source to Destination
try
{
//Read Data from Source
SqlDataReader dr = sqlobject.RunQueryReturnRedaer("Select * from Orders");
sbc.DestinationTableName = "BackUpOrders";
sbc.WriteToServer(dr);
}
catch (Exception ex)
{
evtlog.WriteError(ex.Message);
}
//Read Data from Source
public SqlDataReader RunQueryReturnRedaer(string strSql)
{
SqlCommand cmd = new SqlCommand(strSql, connObj);
createConnection();
SqlDataReader rdr = cmd.ExecuteReader();
return rdr;
}
No comments:
Post a Comment