Reputation: 93
I'm a beginner in using Asp.net MVC5, I am trying to update the records to the database and this always show up.
Here is the screenshot
Here is the code:
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();
strong text
Upvotes: 3
Views: 1341
Reputation: 2479
Remove the comma after the last parameter:
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();
Upvotes: 1