4

I actually try to do an insert on a ADODataset linked on a table with an auto-generated GUID. When I try to get the new ID of my record I get some zero for GUID.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Franck Charlier
  • 414
  • 4
  • 17
  • You will need to save the current bookmark/cursor, use ADODataSet.Requery and restore bookmark/cursor. another option is to try and use `SELECT @@IDENTITY` after the insert (not tested though) – kobik Sep 19 '12 at 10:03
  • I tried this solution. But Requery reload all records... no ? So, it isn't the best practices to obtain the best performances – Franck Charlier Sep 19 '12 at 10:45
  • 2
    You can als initialize the guid to the TAdoDataSet before insert or onnewrecord – Ravaut123 Sep 19 '12 at 10:54
  • Yes! At the moment it's the solution I've choosen. But I would like know the way to use the SQL autogenerated field. :-) – Franck Charlier Sep 19 '12 at 11:11
  • @kobik: Don't use @@IDENTITY but SCOPE_IDENTITY when you have triggers – Ravaut123 Sep 19 '12 at 11:12

1 Answers1

-1

This is an old question but if anyone comes across it...

The big advantage of using GUIDs is that you don't care where they originate from. A value generated as part of a default constraint is no better or worse than a correctly generated GUID in a client program.

@Ravaut123 is correct in that you should just set the GUIDs value when inserting on the TADOataSet set

Clint Good
  • 820
  • 6
  • 14
  • I fail to see how my answer should be down voted. If someone is trying to retrieve a server side generated GUID they clearly don't understand the advantages of GUIDs in the first place. – Clint Good Apr 02 '14 at 23:23