2013-09-29 2 views
3

안녕하세요, SqlDataAdapter에있는 SQL injection을 보호하는 가장 좋은 방법은 무엇입니까? (매개 변수가있는 쿼리를 사용할 방법이 없으므로) 궁금합니다. SqlDataAdapter에서 SQL 삽입을 방지하는 가장 좋은 방법은 무엇입니까?

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(); 

이 시간 내 주셔서 감사합니다 예를 들어

코드의이 부분을 사용할 수 있습니다.

+2

* 매개 변수화 쿼리를 사용 할 수있는 방법이 없기 때문에 * [어 .......] (HTTP :. // MSDN. microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.selectcommand.aspx) –

답변

4

당신은 데이터 어댑터의 SqlCommand 개체에 액세스하는 시도 할 수 있습니다 :

da_services = new SqlDataAdapter("SELECT * from table WHERE [email protected] AND [email protected]", conn); 
da_services.SelectCommand.Parameters.AddWithValue("@column", textBox1.Text); 
da_services.SelectCommand.Parameters.AddWithValue("@column2", somestring); 
관련 문제