你好,我想知道什么是防范的最佳办法SQL injection中SqlDataAdapter(因为没有办法使用参数化查询)?
SQL injection
SqlDataAdapter
例如,让我们使用这部分代码:
da_services = new SqlDataAdapter("SELECT * from table WHERE column='" + textBox1.Text + "' AND column2='" + somestring + "'", conn); scd_services = new SqlCommandBuilder(da_services); dt_services = new DataTable(); da_services.Fill(dt_services); dtg_services.DataSource = dt_services; conn.Close();
感谢您的时间。
您可以尝试访问DataAdapter的SqlCommand对象:
da_services = new SqlDataAdapter("SELECT * from table WHERE column=@column AND column2=@column2", conn); da_services.SelectCommand.Parameters.AddWithValue("@column", textBox1.Text); da_services.SelectCommand.Parameters.AddWithValue("@column2", somestring);