Reputation: 11
When I want to insert records in my table in the database I get this error message: There are fewer columns in the insert statement than specified in the values clause. This is my SQL statement:
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;
Upvotes: 0
Views: 95
Reputation: 1577
When you want to insert a record, the number of columns have to be the same as the number of inserted values. For instance:
INSERT INTO Employees(Name, City, AccountNumber)
VALUES ("John", "London", "0098737602230")
The next statements would fail for example, because the number of column names and inserted values do not match.
INSERT INTO Employees(Name, City)
VALUES ("John", "London", "0098737602230")
INSERT INTO Employees(Name, City, AccountNumber)
VALUES ("John", "London")
I would advise to structure your code a bit. The current statement is not readable by humans and will lead to errors.
Upvotes: 1