DataAdapters and Auto IDs

  • Thread starter Thread starter robin9876
  • Start date Start date
R

robin9876

In asp.net v1.1 I have created a data adapter which has stored
procedures for inserting data which also refreshes the data after the
insert.
How can you get the value of the auto increment field after the accept
changes command has run?
 
If you have the DataAdapter Configuration Wizard 'Refresh the DataSet'
and create the stored procedures, it will update these fields after the
insert/update runs. If you don't want it to create the stored
procedures, try it on a test database and a test DataAdapter to see
what it's actually doing.

In a nutshell, 'Refresh the DataSet' tells the DataAdapter that there
will be an additional parameter for each field in the stored procedure
(OutPut parameter) that once the insert or update stored procedure
runs, it assigns the each fields end result in these output parameters.
Then the DataAdapter will update the appropriate data row with these
output parameter values.

Best regards,

Rick
 
Rick,

AFAIK is this not with OleDB.
You can do this by the way as well without the stored procedure with
SQLClient where it is in my idea standard.

\\\\
cmdInsert
cmdInsert.CommandText = "INSERT INTO Sample(WhatEver) " & _
"VALUES (@WhatEver); SELECT AutoId, " & _
"WhatEver FROM Sample WHERE (AutoId = Scope_Identity())"
cmdInsert.Connection = Conn
cmdInsert.Parameters.Add(New SqlParameter("@AutoId", SqlDbType.Int,
4, "AutoId"))
cmdInsert.Parameters.Add(New SqlParameter("@WhatEver",
SqlDbType.NVarChar, 50, "WhatEver"))
///

Cor
 
Whether or not this is with OleDbDataAdapter, I have found that
implementing return parameters for each field makes it easy to update a
single DataRow with new values that may be updated by the DB Stored
Procedures, or Table Triggers.

Of course, one could just rerun the SelectCommand / Fill the data set
after a Adapter.Update, but that would be slower than refreshing a
single row.

-Rick
 
Thanks, I have now got it to work. I also needed to change a function
to byRef for passing the dataset. I forgot to mention that I was use
the SQL data adpater.
 
Back
Top