How to get the "ID"-column in the "BeforeInsert"-Event?

Hey guys,

I’ve got a mssql-database with a table ‘item’ with 3 columns:

  • item_id
  • name
  • producer_id

These 3 columns are shown in a dhtmlx grid using asp.net and C#.

...
string selectStatement = "SELECT item.item_id, item.name, item.producer_id FROM dbo.item";
dhtmlxGridConnector connector = new dhtmlxGridConnector(selectStatement, "item.item_id", dhtmlxDatabaseAdapterType.SqlServer2005, Database.getConnectionString());
...

In the dhtmlxRequestHandler I also added my own connector_BeforeInsert-Event. But in this event I cant get the ID-value which the user entered. The other 2 fields (name and producer_id) are working fine.

string ItemNumber = e.DataAction.Data[(TableField)"item.item_id"]; // <-- Fires a KeyNotFound-Exception :-( Why?
string ItemName = e.DataAction.Data[(TableField)"item.name"]; // <-- Works fine
string ProducerId = e.DataAction.Data[(TableField)"item.producer_id"]; // <-- Works fine
            
SqlConnection sqlVerbindung = new SqlConnection(Database.getConnectionString());
SqlCommand sqlStatement = new SqlCommand("INSERT INTO dbo.item VALUES('" + ItemNumber + "', '" + ItemName + "', '" + ProducerId + "')", sqlVerbindung);
...

e.DataAction.Data[(TableField)“item.item_id”]; fires a KeyNotFound-Exception :frowning:


Thanks for help…

Hello,
you can access the primary key as e.DataAction.PrimaryKeyValue , it is not stored in DataAction.Data collection

Okay, thank you :slight_smile: