I get the following exception when I Insert a new record from a FormView (updating an existing record works great):
There are no primary key fields specified in the bound control and/or the bound control didn't specify any primary key fields. Update can't continue.
I've read the posts and the online help, and it appears that the most common cause of this problem is a typo in the DataKeyNames property of the formview, however I've triple checked and it appears correct.
This is an example/test application for testing various features of LLBL using a PL connected through Web Service calls to a BL (latest Demo version of LLBLGen).
My PerformWork code is as follows:
protected void dsEmployee_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
{
EmployeeService.Employee ws = new EmployeeService.Employee();
EmployeeEntity employee;
if (e.Uow.GetEntityElementsToUpdate().Count > 0)
{
employee = ws.Update((EmployeeEntity)e.Uow.GetEntityElementsToUpdate()[0].Entity);
}
else
{
employee = ws.Update((EmployeeEntity)e.Uow.GetEntityElementsToInsert()[0].Entity);
}
dsEmployee.EntityCollection.Clear();
dsEmployee.EntityCollection.Add(employee);
}
note: I want to clear the collection and add the returned EmployeeEntity after both the update/insert since there are transformed/calculated field values for the object.
To initiate the update, I have a button on the form which fires the following event:
protected void Update_Click(object sender, EventArgs e)
{
if (fvEmployee.CurrentMode == FormViewMode.Edit)
{
fvEmployee.UpdateItem(false);
}
else
{
fvEmployee.InsertItem(false);
//Response.Redirect("EmployeeEdit.aspx?empID=" + ((EmployeeEntity)dsEmployee.EntityCollection[0]).Empid, true);
}
}
The BL is working fine, the correct record is getting saved to the DB and returned to the PL. The employeeEntity which is added back to the collection after the update has all the correct values (newly generated EmpID specifically).
See attached... Thanks in advance!
Attachments
Filename |
File size |
Added on |
Approval |
employeeEdit.aspx
|
7,717 |
11-Jul-2007 21:57.54 |
Approved |