Language:
كتاب الزكاة
24  
Obligatory Charity Tax (Zakat)
(24)
Chapter: Whoever gave things in charity while he was a Mushrik and then embraced Islam
(24)
باب مَنْ تَصَدَّقَ فِي الشِّرْكِ ثُمَّ أَسْلَمَ
Sahih al-Bukhari 1436

Narrated Hakim bin Hizam:

I said to Allah's Messenger (ﷺ), "Before embracing Islam I used to do good deeds like giving in charity, slave-manumitting, and the keeping of good relations with Kith and kin. Shall I be rewarded for those deeds?" The Prophet (ﷺ) replied, "You became Muslim with all those good deeds (Without losing their reward)."

حَدَّثَنَا عَبْدُ اللَّهِ بْنُ مُحَمَّدٍ، حَدَّثَنَا هِشَامٌ، حَدَّثَنَا مَعْمَرٌ، عَنِ الزُّهْرِيِّ، عَنْ عُرْوَةَ، عَنْ حَكِيمِ بْنِ حِزَامٍ ـ رضى الله عنه ـ قَالَ قُلْتُ يَا رَسُولَ اللَّهِ أَرَأَيْتَ أَشْيَاءَ كُنْتُ أَتَحَنَّثُ بِهَا فِي الْجَاهِلِيَّةِ مِنْ صَدَقَةٍ أَوْ عَتَاقَةٍ وَصِلَةِ رَحِمٍ فَهَلْ فِيهَا مِنْ أَجْرٍ فَقَالَ النَّبِيُّ صلى الله عليه وسلم ‏ "‏ أَسْلَمْتَ عَلَى مَا سَلَفَ مِنْ خَيْرٍ ‏"‏‏.‏
Reference : Sahih al-Bukhari 1436
In-book reference : Book 24, Hadith 39
USC-MSA web (English) reference : Vol. 2, Book 24, Hadith 517
  (deprecated numbering scheme)