int countStart = System.Environment.TickCount; //计算这行代码运行需要多少秒 DataTable dtUser = dbao.LoginUserAll("", deptID); int countEnd = System.Environment.TickCount - countStart; 通过得到两个时间差,得到运行耗时