日期:2014-05-18  浏览次数:20763 次

关于sql注入
SqlCommand cmd = new SqlCommand("select * from WARE where warename='" + TextBox1.Text + "'", conn); 这个可以SQL注入,明白。


//SqlCommand cmd = new SqlCommand("jian", conn); 

   
  //cmd.CommandType = CommandType.StoredProcedure; 

  //cmd.Parameters.AddWithValue("a", TextBox1.Text); 这句话什么意思?

后面注释的三句话是如何做到防止SQL注入的呢?

------解决方案--------------------
探讨
cmd.Parameters.AddWithValue("@a", TextBox1.Text.Replace("'","''"));
使用sqlcommand参数还要TextBox1.Text.Replace("'","''")吗,请问?