SQlite插入不起作用

时间:2012-06-10 16:36:05

标签: c# sqlite

我正在编写一个C#数据库winform应用程序,我在执行此查询时遇到问题。它抛出了这个错误:

SQLite error
near "SELECT": syntax error
是的,有人能帮帮我吗?感谢您的任何回答或建议。

"INSERT into subor(idsubor, idpodfk, pnazovfk, datumpravop, podiel, podield, cislozLV,
datumzaradenia, idmajetok)
values (null, " + comboBox1.SelectedValue.ToString() + ", 
         '" + comboBox2.SelectedValue.ToString() + "', 
         '" + dateTimePicker1.Value.ToString("d. M. yyyy") + "', 
         '" + textBox2.Text + "',
          " + podield.ToString("0.0000", System.Globalization.CultureInfo.InvariantCulture) + ", 
         '" + textBox4.Text + "', 
         '" + dateTimePicker2.Value.ToString("d. M. yyyy") + "', 
              SELECT IFNULL(a, '0') AS idmajetok 
              FROM (SELECT MAX(idmajetok) + 1 AS a FROM subor))";

2 个答案:

答案 0 :(得分:2)

您的C#字符串/ SQLite SQL混合似乎仍然有点令人困惑,但我看到的一个可能的问题如下:

您正在使用SELECT语句指明VALUES列表中的某个值。如您所见in the syntax diagramSELECT语句必须括在括号中。

答案 1 :(得分:0)

我怀疑一些SQL语法问题,我对你的select语句做了一些修改。

请试试:

string sqlInsert = "INSERT into subor(idsubor, idpodfk, pnazovfk, datumpravop, 
podiel,podield, cislozLV, datumzaradenia, idmajetok) values (null, '" + 
comboBox1.SelectedValue.ToString() + "','" + comboBox2.SelectedValue.ToString() + "','" + 
dateTimePicker1.Value.ToString("d.M.yyyy") + "','" + textBox2.Text + "','" + 
podield.ToString("0.0000", System.Globalization.CultureInfo.InvariantCulture) + ",'" + 
textBox4.Text + "','" + dateTimePicker2.Value.ToString("d.M.yyyy") + "','" + "SELECT 
IFNULL(a, '0') AS idmajetok FROM (SELECT MAX(idmajetok) + 1 AS a FROM subor) )');";}