Regex r = new Regex(@"^d+$"); if (r.Match(vlannumber).Success) { sql += " and a.vlannumber=" + vlannumber; } else { sql += " and a.memo like '%" + vlannumber + "%'"; }