Sqlite C#on删除错误没有这样的列。 [英] Sqlite C# on delete error no such column.
本文介绍了Sqlite C#on删除错误没有这样的列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取该列不存在的错误。刚刚开始学习。
请帮忙吗?
Getting error that column does not exist. Just started learning.
Please little help?
System.Data.SQLite.SQLiteConnection sqlite_conn;
System.Data.SQLite.SQLiteCommand sqlite_cmd;
System.Data.SQLite.SQLiteDataReader sqlite_datareader;
private int sqlite_reader;
private void button2_Click(object sender, EventArgs e)
{
sqlite_conn = new System.Data.SQLite.SQLiteConnection("Data Source=D:/main.db;Version=3;");
sqlite_conn.Open();
sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = "DELETE FROM Table WHERE Name ="+comboBox1.Text+"";
sqlite_reader = sqlite_cmd.ExecuteNonQuery();
sqlite_conn.Close();
}
我的尝试:
尝试SELECT * FROM表
DB工作正常。
What I have tried:
Tried SELECT * FROM Table
DB works fine.
推荐答案
试试这个:
Try this:
sqlite_cmd.CommandText = string.Format("DELETE FROM Table WHERE Name ='{0}'", comboBox1.Text);
有关详细信息,请参阅:
SQLite WHERE - 筛选结果集中的行 [ ^ ]
注意:您的代码是 sql注入 [ ^ ]易受伤害。您必须使用参数:
For further details, please see:
SQLite WHERE - Filter Rows in a Result Set[^]
Note: your code is sql injection[^] vulnerable. You have to use parameters:
this.command.CommandText = "DELETE FROM Table1 WHERE Name=@param1";
this.command.CommandType = CommandType.Text;
this.command.Parameters.Add(new SQLiteParameter("@param1", comboBox1.Text));
这篇关于Sqlite C#on删除错误没有这样的列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文