Monday, November 28, 2011

Getting autonumber/identity fields after row add oledb

Adding a row to a table where autonumber is set on the field means you don't know the autonumber field contents until after the row has actually been added. This is problematic when you're doing some referential integrity in oledb.

To determine the autonumber field contents, execute the following just after the row is added

Dim cmdNewID As New OleDbCommand("SELECT @@IDENTITY", TheOledbDataConnection)

Dim NewTakeoffId as Integer = cmdNewID.ExecuteScalar

No comments:

Post a Comment