.net SqlCommand.Parameters.AddWithValue注入安全吗?

.net SqlCommand.Parameters.AddWithValue注入安全吗?,.net,parameters,sql-injection,sqlcommand,sql-parametrized-query,.net,Parameters,Sql Injection,Sqlcommand,Sql Parametrized Query,SqlCommand.Parameters.AddWithValue方法注入是否安全 它接受有效负载的对象,因此它如何防止注入?这实际上取决于您如何使用它们 看到这里的区别了吗。第一个是安全的,但第二个不是 sqlCommand.CommandText = "select * from Books where Title = @title"; sqlCommand.Parameters.AddWithValue("title", txtTitle.Text); 有关详细信息,请访问 str

SqlCommand.Parameters.AddWithValue方法注入是否安全


它接受有效负载的
对象,因此它如何防止注入?

这实际上取决于您如何使用它们

看到这里的区别了吗。第一个是安全的,但第二个不是

sqlCommand.CommandText = "select * from Books where Title = @title";
sqlCommand.Parameters.AddWithValue("title", txtTitle.Text);


有关详细信息,请访问

string sql = "select * from Books where title = " + txtTitle.Text;
sqlCommand.CommandText = "exec(@sql)";
sqlCommand.Parameters.AddWithValue("sql", sql);