【发布时间】:2015-08-13 07:12:18
【问题描述】:
我想在 c# 中将数据插入到 sqlite 数据库中。我正在使用 WinForms。我收到了一个异常 FileLoadException。
SQLiteConnection con = new SQLiteConnection(@"Data Source=c:\\sqlite\\mySqliteDb.sqlite;Version=3;New=True;Compress=True;");
private void InsBtn_Click(object sender, EventArgs e)
{
try
{
con.Open();
string Query = "insert into sqliteDb(ID,Name) values('"+this.textBox1.Text + "','" + this.textBox2.Text + "')";
SQLiteCommand cmd = new SQLiteCommand(Query,con);
cmd.ExecuteNonQuery();
con.close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
【问题讨论】:
-
在哪一行抛出这个异常?
sqliteDb表中的列类型是什么?而且您应该始终使用parameterized queries。这种字符串连接对SQL Injection 攻击开放。