这是用于进行搜索的代码
private void button1_Click(object sender, EventArgs e)
{
string connectionString = Tyre.Properties.Settings.Default.Database1ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM table1 where Nom like " + textBox1.Text, conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
}
我收到这个错误
System.Data.dll 中发生“System.Data.SqlClient.SqlException”类型的未处理异常
附加信息:无效的列名“elie”。
thats a exemple of my application :
Click here to see the image
首先,你的代码是开放的SQL注入。您允许用户插入他想要的任何数据,包括
;删除表表1
要解决围绕要与单引号和 % 符号匹配的项目的直接问题:
"SELECT * FROM table1 where Nom like '%" + textBox1.Text + "%'"
然而,你绝对地应该考虑使用参数化查询.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)