防止SQL注入的参数化方法

来源:互联网 发布:stc15系列单片机 编辑:程序博客网 时间:2024/05/22 01:29
最好的方法就是用参数化SQL:
SqlConnection cn=new SqlConnection("连接字符串");
SqlCommand cmd=new SqlCommand("insert into 表 values(@name,@pwd)",cn);
cmd.Paramters.AddWithValue("@id",TextBoxName.Text);
cmd.Paramters.AddWidthValue("@pwd",TextBoxPwd.Text);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();