What happens when you swear to not do something but you do it? And what should you do?
Whether you swear or simply stated that you were not going to do something, that is sufficient to bind a Christian. A Christian is a man of his word. Swearing isn't required to make a Christian more honest. "But let your 'Yes' be 'Yes,' and your 'No,' 'No.' For whatever is more than these is from the evil one" (Matthew 5:37).
When a person gives his word and then breaks it, at the foundation is a lie. "Do not be rash with your mouth, and let not your heart utter anything hastily before God. For God is in heaven, and you on earth; therefore let your words be few" (Ecclesiastes 5:2). A Christian who lies needs to come before his God and admit his error. "If we confess our sins, He is faithful and just to forgive us our sins and to cleanse us from all unrighteousness" (I John 1:9). For the one who counted on our word and was wrong, we also should apologize and, if possible, make amends for our wrong.
There are times when a person says he will do (or not do) something that in itself is wrong. A promise to sin is not to be kept -- it should not have been made in the first place. Again, confessing our error before God is required and effort should be made to correct the sin that we did toward others.
But when a person rashly states something, he is required to keep his word, even if it leads to his own discomfort. "In whose eyes a vile person is despised, but he honors those who fear the LORD; he who swears to his own hurt and does not change" (Psalm 15:4). Even when deceit is involved by another, a Christian is expected to still keep his word.