follow up on autoimcrements (David Sceppa's book)

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

I read David Sceppa's ADO.NET book, and in particular I have read his
methods for retrieving timestamp and autoincrement values from both sql and
access databases... I am using his method accept that in my simple insert
scenario I am not using a dataAdapter and a Dataset, and therefor no
rowUpdating event either. I am just using my own queries. I want to verify
that what I am doing is ok... more precisely, I want to verify that I did
not break some kind of 'glue' that his exact example used. I need to make
sure that if multiple users were using the app that the autoincrement values
I am retrieving to create child records would remain accurate. I think they
would since I'm using the same connection object for both commands... hope
I'm right : )

heres what I'm doing. Please let me know if its ok.

1) define first insert command and parameters.
2) define the second command to get identity (select @@identity) using same
connection as the first insert command.
3) open connection.
4) execute insert command.
5) execute get identity comand and store value in a variable.
6) define insert command for the child records using the indentity
retrieved.
7) execute insert command for child records.

any info is appreciated. Thanks.

I would highly reccomend David Sceppa's book on ADO.NET. Its a Microsoft
Press book. Very thorough and clear explanations and examples.
 
If you are daisy chaining commands to a single command object, with SQL
Server, get SCOPE_IDENTITY rather than @@Identity.

It is better to encapsulate the logic in stored procedures than daisy
chaining commands, however.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
thanks for the reply Gregory. I should have made it clear that I am using
Access for this particular task. So stored procedures and batch queries are
not supported. I know, I would not use Access for a production app. This is
a learning experiment for me.

So, taking into account that I am using access, does what I did look ok?
safe?

thanks.
 
You have the right approach. If you're submitting your pending changes
using a DataAdapter, use the RowUpdated event to fire off the @@IDENTITY
query.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2004 Microsoft Corporation. All rights reserved.
 
No problem. And thank you for the kind words.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2004 Microsoft Corporation. All rights reserved.
 
Back
Top