A clamping device for clamping a portable electronic device is provided. The clamping device includes a mounting board and a clamping mechanism. The clamping mechanism includes two adjusting members, two sliding blocks, and a sliding rail. The adjusting members can adjust the positions of the sliding blocks on the sliding rail. The sliding rail is selectively attached to the mounting board, either horizontally or vertically.