ExecuteNonQuery 只在insert,update,delete时才返回受影响行数 在select时总是返回-1
把代码写成:
string strSql = "Select count(*) from ClsInfo where ClsName='"+ClsName+''";
int num=Convert.ToInt32(cmd.ExecuteScalar(strSql));
int num=Convert.ToInt32(cmd.ExecuteScalar(strSql));
就可以用num接受受影响行数