public static int CountByCourse(Command cmd,string courseId) { string table = Selection.Table; string sql = string.Format(@"select count(*) from {0} where lower(Course_Id)=lower(@Course_Id)", table); cmd.CommandText = sql; cmd.AddParameter("@Course_Id", courseId); object count = cmd.ExecuteScalar(); return (count == null || count is DBNull) ? 0 : Convert.ToInt32(count); }