How do I re-write a SQL query as a parameterized query?

后端 未结 2 800
日久生厌
日久生厌 2020-11-29 14:17

I have heard that I can prevent SQL injection attacks by using parameterized queries, but I do not know how to write them.

How would I write the following as a param

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 14:52

    instead of comboBox1.Text use parameters like @firma

    command.Parameters.Add("@firma", SqlDbType.Varchar);
    command.Parameters["@firma"].Value = comboBox1.Text;
    
     query += " AND firma = @firma ";
    

    apply this to all parameters

提交回复
热议问题