Click here to Skip to main content
15,892,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this error happened when try to add new row in gridview ado.net
Quote:
AddNew cannot be called on the 'Company.BLL.Entity.Employee' type. This type does not have a public default constructor. You can call AddNew on the 'Company.BLL.Entity.Employee' type if you handle the AddingNew event and create the appropriate object.



the code that addes new row

C#
employeeBindingSource.AllowNew = true;

            employeeBindingSource.AddNew();
            EmployeeManager.InsertEmployee(
                (employeeBindingSource.Current as Employee).Name,
                (employeeBindingSource.Current as Employee).Salary,
                (employeeBindingSource.Current as Employee).DepartmentID,
                (employeeBindingSource.Current as Employee).Age
                );
Posted
Comments
Sinisa Hajnal 2-Apr-15 2:12am    
As the error explains, you have to have public default constructor. That means that you have to have public New() method without parameters. In other words if you can call New Employee () you are good to go.

Or you can handle AddingNew event - but you're probably better off just having default constructor setting default values to the employee fields.
TheSniper105 2-Apr-15 12:31pm    
can you please write code explain this part
you're probably better off just having default constructor setting default values to the employee fields.

in answer so i can mark it accepted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900