本文介绍了变量名'@ newhealth'已经被声明。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在用户攻击时调用的函数。我正在尝试更新敌人的健康状况,并表示@newhealth已经宣布。 除了UPDATE,我还应该使用其他东西吗? 我也试过使用AddWithValue("@ newhealth",newEnemyHealth)
并说明了同样的事情。

 if(userAtk> = enemydef)
{
userDmg =(userAtk - enemydef)+ d4;
newEnemyHealth = enemyHealth - userDmg;
cmdHealth.Connection = conn;
cmdHealth.CommandText =" UPDATE characterStats将health = @newhealth FROM characterStats设置为cs WHERE cs.name = @name;" ;;
cmdHealth.Parameters.Add(new SqlParameter(" @ newhealth",SqlDbType.Int))。Value = newEnemyHealth;
cmdHealth.Parameters.AddWithValue(" @ name",enemy);
cmdHealth.ExecuteNonQuery();
}



解决方案

This is in a function I call when the user attacks. I am trying to update the enemies health and it states @newhealth has already been declared.  Should I use something else besides a UPDATE here?  I also tried using AddWithValue("@newhealth",newEnemyHealth) and stated the same thing.

 if (userAtk >= enemydef)
            {
                userDmg = (userAtk - enemydef) + d4;
                newEnemyHealth = enemyHealth - userDmg;
                cmdHealth.Connection = conn;
                cmdHealth.CommandText = "UPDATE characterStats Set health = @newhealth FROM characterStats as cs WHERE cs.name = @name;";
                cmdHealth.Parameters.Add(new SqlParameter("@newhealth", SqlDbType.Int)).Value = newEnemyHealth;
                cmdHealth.Parameters.AddWithValue("@name", enemy);
                cmdHealth.ExecuteNonQuery();
}


解决方案


这篇关于变量名'@ newhealth'已经被声明。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 09:37