Menu

SQL Bulk Copy

You have upload Multiple Record at a time in  asp.net


using (SqlConnection DirectionConnection = newSqlConnection("YourConnectionString"))
{
        DirectionConnection.Open();
        using (SqlTransaction transaction = DirectionConnection.BeginTransaction())
       {
         using (SqlBulkCopy bulkCopy = new SqlBulkCopy(DirectionConnection,
                       SqlBulkCopyOptions.KeepIdentity, transaction))
          {
        SqlBulkCopyColumnMapping CountryName = new SqlBulkCopyColumnMapping("CountryName", "CountryName");
        // Map Your "Sql Table" Filed Name with your "Data Table" Filed
        bulkCopy.ColumnMappings.Add(CountryName);
        // Pass Sql Table Name
        bulkCopy.DestinationTableName = "Country";
        bulkCopy.WriteToServer(ds.Tables[0]);
        transaction.Commit();
       }
  }
}

No comments

Leave a Reply


6 + 2 =

Categories