ExecuteNonQuery不返回值?

Abh*_*jan 2 .net c# t-sql sql-server ado.net

我正在尝试编写一个常用的Save函数,我正在使用它Dbcommand.我的代码是:

private static int Save(CommandType commandtype, string commandText, SqlParameter[] commandParameters, bool p)
{
    int id = -1;

    using (DbConnection connection = factory.CreateConnection())
    {
        connection.ConnectionString = connectionString;
        using (DbCommand command = factory.CreateCommand())
        {
            command.Connection = connection;
            command.CommandType = commandtype;
            command.CommandText = commandText;
            foreach(SqlParameter pa in commandParameters)
            {
                command.Parameters.Add(pa);
            }
            connection.Open();
            id = command.ExecuteNonQuery();
        }
    }
    return id;
}
Run Code Online (Sandbox Code Playgroud)

我哪里错了?代码将值保存在数据库中.

nav*_*val 5

请删除SP SET NOCOUNT ON中的行; 在SP中,您将获得价值