这个判断字段存在的语法哪里存在错误呢

  string StrSql = "select count(*)from" + TableName + "where Name= '" + SlecetName.Trim() + "'";

改成这样试试看呢 

string StrSql = "select count(*) from" + TableName + " where Name = '" + SlecetName.Trim() + "'";

 

count(*)from === from前来个空格

 "where Name= '"===where前来个空格

拼接SQL时需要注意变量与字符串之间的空格,空格添加在字符里

string StrSql = "select count(*) from " + TableName + " where Name= '" + SlecetName.Trim() + "'";

把空格补上,你不加空格把语句中的单词分开,代码执行的时候两个单词合到一起了,不符合数据库语句规范,数据库怎么知道你这句话是干啥的。还是不清楚就打个断点,调试的时候把拼接好的sql语句复制到数据库中执行一下,看能不能正常执行