我编写了以下函数来更新我的数据库中的学生:
public bool UpdateStudent(Student stu)
{
Console.WriteLine("StudentManger.UpdateStudent): Called");
int rowsChanged = 0;
using (var cnn = new SqlConnection(
Properties.Settings.Default.universityConnectionString))
{
using (var cmd = new SqlCommand("UPDATE Student " +
"SET FirstName = @FirstName, " +
"lastName = @LastName, " +
"birth = @birth " +
"WHERE id = @id", cnn))
{
cmd.Parameters.Add(new SqlParameter("@FirstName", stu.FirstName));
cmd.Parameters.Add(new SqlParameter("@LastName", stu.LastName));
cmd.Parameters.Add(new SqlParameter("@id", stu.ID));
cmd.Parameters.Add(new SqlParameter("@birth", stu.Birth));
cnn.Open();
rowsChanged = (int)cmd.ExecuteNonQuery();
Properties.Settings.Default.Save();
}
}
Properties.Settings.Default.Save();
return (rowsChanged != 0);
}
但是当我调用函数时,实际上没有数据被保存到数据库中
有人能告诉我为什么吗?