Many tutorials I've seen compose SQL statements by using variables and Parameters.Add
, like this:
public void updateStudent(String @studentID, String @firstName, String @lastName)
{
SQLiteCommand command = conn.CreateCommand();
command.CommandText = "UPDATE Students SET firstName = @firstName, lastName = @lastName WHERE studentID = @studentID";
command.Parameters.Add(new SQLiteParameter("@studentID", @studentID));
command.Parameters.Add(new SQLiteParameter("@firstName", @firstName));
command.Parameters.Add(new SQLiteParameter("@lastName" , @lastName));
command.ExecuteNonQuery();
}
Why don't we use
string.Format("Update Students SET firstName = '{0}', lastName = '{1}...", @firstName, @lastname)
instead?