得到一个名为Player的数据库表,得到的值是Level SMALLINT和Experience SMALLINT + others。如果经验等于50或更高,我想将等级提高到2;我已尝试过这个以及其他一些事情:
SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
SqlCommand CheckStat = new SqlCommand("SELECT * FROM Player WHERE UserID=@uid", connection);
string uID = Session["userID"].ToString();
CheckStat.Parameters.AddWithValue("@uid", uID);
try
{
connection.Open();
SqlDataReader StatReader = null;
StatReader = CheckStat.ExecuteReader();
if (StatReader.Read())
{
ExperienceLabel.Text = "Experience: " + StatReader["Experience"].ToString();
EnergyLabel.Text = "Energy: " + StatReader["Energy"].ToString();
GoldLabel.Text = "Gold: " + StatReader["Gold"].ToString();
int Experience = Convert.ToInt32(StatReader["Experience"]);
if (Experience >= 50)
{
SqlCommand Level2 = new SqlCommand("UPDATE Player SET player.Level=2 WHERE UserID=@uid", connection);
try
{
connection.Open();
Level2.ExecuteNonQuery();
}
catch (Exception ex)
{
// Error handling
LevelLabel.Text = (ex.Message);
}
finally
{
connection.Close();
}
}
}
}
catch (Exception ex)
{
ExperienceLabel.Text = (ex.Message);
}
答案 0 :(得分:0)
您似乎没有向SqlCommand Level2
提供@uid
参数。