动软生成代码中的DBhelperSQL.ExecuteSql()

    这个函数,实现主要是

    SqlConnection connection = new SqlConnection(strSqlcon);

    SqlCommand cmd = new SqlCommand(SqlString,connection);

    int iRow = cmd.ExcuteNonQuery();

    执行语句返回行数。看似是执行什么语句都可以。查一下MSDN,最重要的部分:

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

注意最后一句,all other ...,除了update ,insert,delete其余的都是会返回-1.
    于是我改用了cmd.ExecuteScalar();如果执行无影响,会返回null。
    

猜你喜欢

转载自blog.csdn.net/qq_35315154/article/details/80309829