Command Builder in tables without primary key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi every one, i'm trying to use a sqlcommandbuilder in an application using a
table without a primary key, when i call the DataAdapter.Update Method there
comes an Error saying that "the selectcommand does not return information
about the primary key" or some thing like that...
Does some one knows a way to implement the command builder or similar method
to work around on updating tables with out primary key??
 
Wichury said:
Hi every one, i'm trying to use a sqlcommandbuilder in an application
using a
table without a primary key, when i call the DataAdapter.Update Method
there
comes an Error saying that "the selectcommand does not return information
about the primary key" or some thing like that...
Does some one knows a way to implement the command builder or similar
method
to work around on updating tables with out primary key??

All tables should have a primary key.

And, no. It's not even theoretically possible. How would you locate rows
to update?

For such a dubious enterprise you will have to build your own commands.

David
 
No can do - all of the autogenerated stuff needs a key. But with all do
respect, it's probably worth adding a key - The dogma of Every table should
have a key is pretty sound ;-)
 
Wilchury -

If you don't have a key, what would you specify in your where clause for the
update? More so - ask it this way - how would you write an automatic class
like the CommandBuilder - to automatically generate an UpdateStatement for
you - when it cannot be sure of what it is updating?

BTW, When you do get a command from CommandBuilder - check the CommandText
for that - it is hyper ugly and inefficient. (Of course - automatic tool -
one size fits all - it can't be good). So, I'd recommend writing up your own
CommandText.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
Back
Top