Ok which laptop is this?
It could be several things. Some laptops have power management schemes that basically if you have it set to max performance all the time, it will shut down when disconnected from power. So make sure that's set to balanced or whatever equivalent for balanced is for your laptop.
Otherwise, if this isn't it, then it's probably either the bad battery or battery connection. In either case that is something you'd take to the repair shop (or send back to dell, hp, lenovo or whoever makes your laptop), for them to fix for you and replace your battery.