我正在尝试更新列中的一个单元格, 在调试模式下,它通过整个代码,但它从来没有因某种原因受到影响。而且没有任何错误。
这是我的代码:
else//wrong try!
{
int errors;
string gameHistory = Request.QueryString[0];
errors = int.Parse(gameHistory);
string query = "UPDATE HistoryOfGames SET NumberOfErrors=@NumberOfErrors WHERE ID='"+gameHistory+"'";
con = new SqlConnection("Data Source=MICROSOF-58B8A5\\SQL_SERVER_R2;Initial Catalog=Daniel;Integrated Security=True");
con.Open();
string query2 = "SELECT NumberOfErrors FROM HistoryOfGames WHERE ID='"+gameHistory+"'";
SqlCommand command = new SqlCommand(query2, con);//checks how much errors was in the last time played.
errors =(int)command.ExecuteScalar();
command = new SqlCommand(query, con);
command.Parameters.AddWithValue("@NumberOfErrors", errors);//set a new error.
command.ExecuteNonQuery();
con.Close();
}
谢谢!
答案 0 :(得分:1)
使用SQL Server Profiler检查服务器上执行的查询。
答案 1 :(得分:1)
我认为你的代码是写的,但是语句的顺序是错误的。
请检查一下,
command = new SqlCommand(query, con);
command.Parameters.AddWithValue("@NumberOfErrors", errors);//set a new error.
command.ExecuteNonQuery();
SqlCommand command = new SqlCommand(query2, con);//checks how much errors was in the last time played.
errors =(int)command.ExecuteScalar();
con.Close();
首先更新错误,然后选择它。
答案 2 :(得分:0)
就像有人建议的那样,我从来没有改变过“错误”整数,也没有把它增加一个。
感谢所有帮助者!