Command Builder in tables without primary key

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??
 
D

David Browne

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
 
W

W.G. Ryan eMVP

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 ;-)
 
S

Sahil Malik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top