TableAdapter and Identity Column Values after INSERT

  • Thread starter Thread starter Mark Olbert
  • Start date Start date
M

Mark Olbert

It appears that the neither the TableAdapter DbDirect methods nor the TableAdapter Update method update identity column values with
the values after an INSERT operation.

Is this correct?

If so, what is the best way of retrieving the identity column value?

- Mark
 
Hi Mark,

By default, the TableAdapter will not add SELECT statement after insert or
update. However, you can do the following to make the designer add it for
you.

1. Right click on the TableAdapter and select configure... from the pop up
menu.
2. In Advanced Options, check Refresh the datatable, and click OK.
3. Click Finish.

Make sure that a primary key field exists in the table, or the SELECT
statement cannot be generated.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I don't know how I missed that.

Is this a change in the default behavior of DataAdapters (and yes, I know that a TableAdapter isn't a DataAdapter...but they're
positioned to "solve" similar problems)? I don't recall having to tell the SqlDataAdapter designer to refresh after update and
insert.

- Mark
 
I should also have asked this question in my followup: what are the circumstances under which I >>wouldn't<< want to configure
TableAdapters that were going to be used for inserts and updates to refresh after the operation? What are the downsides to selecting
the refresh option?

I presume there must be some, or it would be the default.

- Mark
 
Mark,

I think that we have missed that allmost all.

Jesus Lopez has made a message last week in the newsgroup.

Before that time all answers in the English dotnet Newsgroups about this
question had another answer than this.

Cor
 
If you're just doing fire-and-forget inserts, such as logging or auditing or
anything where you don't need the data after it's been inserted, then the
post-insert SELECT would just be a pointless overhead. That said, I'd say
that "Refresh" should be selected by default.
 
Hello Kevin:

Great Post. However, I'm having a problem with the steps you described
below. The "Refresh the Data Table" option on my TableAdapter is disabled
("grayed out") so I can not select it. Do you know what the problem may be?

My scenario is this: My DB is Firebird, my connection type is ODBC
(although I have a native driver too). The control is enabled using the
native driver, but then other issues arise so I'm tending to not use it right
now.

Thanks in advance for any help.

Tony
(e-mail address removed)
 
Back
Top