【发布时间】:2013-11-16 19:40:43
【问题描述】:
我在很多教程中看到使用变量和参数组成 sql 语句。添加喜欢这个
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();
}
我们为什么不使用
string.Format("Update Students SET firstName = '{0}', lastName = '{1}...", @firstName, @lastname)
有什么好处吗??
【问题讨论】: