Insert multiple rows from DataGridView
Posted: Mon 18 Apr 2011 13:28
Hello,
I'm using VS2008, .NET 3.5 SP1 and dotconnect 6.0 for Oracle. The Database is Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit. I have one table with one primary key column and one date column. On insert, I pull the primary key from a sequence and set the date to the current date with a trigger. This is tested and works fine from within sqldeveloper.
In VS I generate an entity model from the Database. I bind the table representation in the entity with a bindingsource to a datagridview.
If I insert *1* new row into the datagridview and then save the changes, everything works fine.
When I create more than one new row, I get the following error:
In the ef model, I set the default value for the primary key column to -1. The Entity Key property is true. I tried to set "Store Generated Pattern": Identity/Computed - nothing worked. I also set the date column to Store Generated Pattern: Computed.
Even in the working case (insert 1 row) I am missing on thing: I would expect the computed columns to be read back from the database and displayed in the datagridview, at least when I call refresh on the form
But this does not happen either.
Also, I would be curious about one thing - when I add a new row to the datagridview and call SaveChanges() on the entity, it is saved, but I do not see the new object in the entity collection. How do I achieve this?
I'm using VS2008, .NET 3.5 SP1 and dotconnect 6.0 for Oracle. The Database is Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit. I have one table with one primary key column and one date column. On insert, I pull the primary key from a sequence and set the date to the current date with a trigger. This is tested and works fine from within sqldeveloper.
Code: Select all
CREATE OR REPLACE TRIGGER "TRG_LDD_BIUR"
before INSERT OR UPDATE ON T_LINEDOWNDEVICES
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH row BEGIN
IF inserting THEN
IF :new.ldd_id IS NULL OR :new.ldd_id < 1 THEN
SELECT seq_linedown.nextval INTO :new.ldd_id FROM dual;
END IF;
:new.erstdatum := sysdate;
END IF;
IF updating THEN
:new.editdatum := sysdate;
END IF;
END;
Code: Select all
MyModel.MyEntities ent = new MyModel.MyEntities();
tLinedowndeviceBindingSource.DataSource = ent.TLinedowndevices;
Code: Select all
dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
ent.SaveChanges();
Besides the wording of the error message, not all rows are saved correctly.The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
In the ef model, I set the default value for the primary key column to -1. The Entity Key property is true. I tried to set "Store Generated Pattern": Identity/Computed - nothing worked. I also set the date column to Store Generated Pattern: Computed.
Even in the working case (insert 1 row) I am missing on thing: I would expect the computed columns to be read back from the database and displayed in the datagridview, at least when I call refresh on the form
Code: Select all
this.Refresh();
Also, I would be curious about one thing - when I add a new row to the datagridview and call SaveChanges() on the entity, it is saved, but I do not see the new object in the entity collection. How do I achieve this?