delphi-2010 - 在表中插入记录会导致错误消息
问题描述
当我想在数据库中的表中插入记录时,我收到此错误消息:插入语句中的列数少于值子句中指定的列数。这是我的 SQL 语句:
dm.qr_emp.SQl.Add( 'insert into emp_per(nom, prenom, date_naiss1, cle_ccp,nomf,prenomf,' +
'lieu_naiss,sex,adr,id_corps,id_fonction,id_categ,montant_resp,' + 'compte_ccp,etat,sal_base,id_grade,id_banque,id_degree,sal_unique,' +'pfc,iep,num_social,sal_principale,ind,salaire,montant_irg,' +
'ss,nbr_enfant,nbr_enfant_sup,bource_f,irg,retenue) '
);
dm.qr_emp.SQL.Add
('values('+quotedstr(edit1.Text)+', '+quotedstr(edit2.Text)+','+quotedstr(formatdatetime('yyyy-dd-mm',datetimepicker1.DateTime))+', '+
edit4.Text+','+quotedstr(edit5.Text)+','+quotedstr(edit3.Text)+','+quotedstr(edit6.Text)+','+quotedstr(ComboBox3.Text)+','+quotedstr(edit8.Text)+','+ inttostr(id_corps)+','+ inttostr(id_fonction)+',
'+quotedstr(edit10.Text)+','+floattostr(salair_responsabilite)+','+quotedstr(edit7.Text)+','+quotedstr(ComboBox5.Text)+','+floattostr(salaire_base)+','+ inttostr(id_grade)+','+ inttostr(id_banque)+','+
inttostr(id_degree)+','+quotedstr(ComboBox8.Text)+','+
floattostr(pfc)+','+quotedstr(edit15.Text)+','+quotedstr(edit13.Text)+','+
floattostr(sal_principale)+','+floattostr(ind)+','+quotedstr(edit20.text)+',+'+floattostr(montant_irg)+','+floattostr(ss)+', '+(edit23.Text)+',
'+quotedstr(edit26.Text)+','+floattostr(boursef)+','+quotedstr(edit21.Text)+','+
floattostr(retenu)+')');
dm.qr_emp.ExecSQL;
解决方案
当您要插入记录时,列数必须与插入值的数量相同。例如:
INSERT INTO Employees(Name, City, AccountNumber)
VALUES ("John", "London", "0098737602230")
例如,下一个语句将失败,因为列名和插入值的数量不匹配。
INSERT INTO Employees(Name, City)
VALUES ("John", "London", "0098737602230")
INSERT INTO Employees(Name, City, AccountNumber)
VALUES ("John", "London")
我会建议您稍微结构化一下您的代码。当前的语句是人类无法阅读的,并且会导致错误。
推荐阅读
- python - 按列分组并重新采样日期并获得其他列的滚动总和
- common-lisp - 使用 cond 运算符的 Parens 'options'?
- r - 是否可以在 R 中的地理包上运行 sql 几何函数
- r - 第一行作为数据框列表中的列名 (2)
- qt - QML Animation: How to stop infinite animation in exact position?
- google-app-engine - 通过部署管理器创建 App Engine 期间出现内部错误
- forms - 使用 locallang.xlf 以typo3 形式翻译自定义validationErrorMessages
- python - 为什么 W-DAY 在 Pandas 中的行为令人困惑?
- tensorflow - 将 keras 模型导出为 tf savedModel 格式:如何修复 serving_input_fn
- mysql - 修复第 2 行 init.php 中 root'@'localhost' 的访问被拒绝(使用密码:NO)