I have a web application in visual studio where I am getting the following message whenever I try to give an insert command
System.Data.SqlClient.SqlException: 'An explicit value for the identity column in table'
C # code:
SqlDataSource1.InsertCommand = "SET IDENTITY_INSERT Funcionario ON " +
"INSERT INTO Funcionario VALUES ('" + func.nome + "'," + func.salarioBase + "," + func.inss + "," + func.irrf + "," + func.hrsExtras + "," + func.dependentes + "," + func.salarioLiquido + ")" +
"SET IDENTITY_INSERT Funcionaio OFF";
SqlDataSource1.Insert();
Table structure:
create table Funcionario(cod_Func int identity (1,1),nome varchar (50),salarioBase decimal,inss decimal,irrf decimal,qtdHoraExtra int,dependente int,salarioLiquido decimal);
If I try to insert specifying the fields of the table, the error becomes another
Insert:
SqlDataSource1.InsertCommand = "SET IDENTITY_INSERT Funcionario ON " +
"INSERT INTO Funcionario (nome,salarioBase,inss,irrf,qtdHoraExtra,dependente,salarioLiquido) VALUES ('" + func.nome + "'," + func.salarioBase + "," + func.inss + "," + func.irrf + "," + func.hrsExtras + "," + func.dependentes + "," + func.salarioLiquido + ")";
SqlDataSource1.Insert();
Error:
System.Data.SqlClient.SqlException: 'There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement. '
I do not understand why the error, since cod_Func
is identity , that is, we can not set its value.