0

我正在编写一个 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))";
4

2 回答 2

2

您的 C# 字符串/SQLite SQL 组合似乎仍然有些混乱,但我看到的一个可能问题如下:

您正在使用SELECT语句来指示列表中的一个值VALUES。正如您在语法图中看到的那样,该SELECT语句必须用括号括起来。

于 2012-06-10T17:05:24.423 回答
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) )');";}
于 2012-06-10T16:41:30.020 回答