我是使用Asp.net MVC5的初学者,我正在尝试将记录更新到数据库,这总是显示出来。
这是截图
以下是代码:
SqlConnection con = new SqlConnection(DAL.cs);
con.Open();
SqlCommand com = new SqlCommand("UPDATE Student SET LastName = @LastName," +
"FirstName = @FirstName," +
"MiddleName = @MiddleName," +
"WHERE ID = @ID", con);
com.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = s.ID;
com.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = s.LastName;
com.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = s.FirstName;
com.Parameters.AddWithValue("@MiddleName", SqlDbType.VarChar).Value = s.MiddleName;
com.ExecuteNonQuery();
con.Close();
强文
答案 0 :(得分:1)
删除最后一个参数后的逗号:
SqlConnection con = new SqlConnection(DAL.cs);
con.Open();
SqlCommand com = new SqlCommand("UPDATE Student SET LastName = @LastName," +
"FirstName = @FirstName," +
"MiddleName = @MiddleName " +
"WHERE ID = @ID", con);
com.Parameters.AddWithValue("@ID", SqlDbType.Int).Value = s.ID;
com.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = s.LastName;
com.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = s.FirstName;
com.Parameters.AddWithValue("@MiddleName", SqlDbType.VarChar).Value = s.MiddleName;
com.ExecuteNonQuery();
con.Close();