Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
bulkcopy can done only by using datareader or we can use data set to done bulkcopy...
public static void PerformBulkCopy()
    {
        string connectionString = "Server=CBMWEBREN15;Database=jahan;Trusted_Connection=true";
        {
            try
            {
                SqlConnection sourceConnection = new SqlConnection(connectionString);
               
                    SqlCommand myCommand = new SqlCommand("select * from j22", sourceConnection);
                    sourceConnection.Open();
                    SqlDataReader myReader = myCommand.ExecuteReader();
                    SqlConnection destinationConnection = new SqlConnection(connectionString);
                 
                        destinationConnection.Open();
                        SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection.ConnectionString);
                  
                            bulkCopy.BatchSize = 40;
                            bulkCopy.NotifyAfter = 30;
                            bulkCopy.SqlRowsCopied += new SqlRowsCopiedEventHandler(bulkCopy_SqlRowsCopied);
                            bulkCopy.DestinationTableName = "j2";
                            bulkCopy.WriteToServer(myReader);
                    
                        destinationConnection.Close();
                   
                    myReader.Close();
                    sourceConnection.Close();
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

the above code is working but is there any possible to get dataset from arraylist and store it to database using bulkcopy... if u know means tel me
Posted

 
Share this answer
 
v2
mySqlDataAdapter.Update(myDataSet,"TableName");
 
Share this answer
 
v4
Comments
Toniyo Jackson 13-Apr-11 7:06am    
Use pre tag for code

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