【发布时间】:2012-03-22 07:18:16
【问题描述】:
您好,以下代码出现语法错误。我不知道如何解决问题。
错误
{"SQLite 错误\r\nnear \"Mytext\": 语法错误"}
我的代码
string dataSource = "Database.s3db";
SQLiteConnection connection = new SQLiteConnection();
connection.ConnectionString = "Data Source=" + dataSource;
connection.Open();
SQLiteCommand command = new SQLiteCommand(connection);
command.CommandText = ("update Example set Info ='" + textBox2.Text + ", Text ='"+textBox3.Text + "where ID ='" + textBox1.Text +"'");
command.ExecuteNonQuery();
【问题讨论】:
-
为避免此类错误(和 SQL 注入),您应该使用查询参数,而不是动态创建 SQL 命令字符串。
-
@user1248067:请不要按原样使用已接受的答案。您应该真的,真的使用参数化 SQL。