3
我是使用Asp.net MVC5的初學者,我試圖將記錄更新到數據庫,並且始終顯示。在System.Data.dll中發生類型'System.Data.SqlClient.SqlException'的異常
下面是截圖
這裏是代碼:
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();
強大的文本
「@ MiddleName」後的逗號# – ninja