You have to associate that behavior with a negative response, usually pain. I don't mean hurt him bad enough to leave a mark!.
If he's small enough rub his nose in it and throw him out the door.
If that's not practical, use a shock collar and light him up in the act, then get him outside
You might kennel him up, most don't won't go where they sleep, and when your ready to let him out take him outside 1st.
I do a lot for my kids but wouldn't house train their dog, in my house anyway.