|
-
Feb 22nd, 2015, 03:53 PM
#1
Thread Starter
Fanatic Member
-
Feb 22nd, 2015, 11:34 PM
#2
Re: System.InvalidOperationsException
That error message indicates that at least one of your table adapters doesn't have its DeleteCommand set.
When you create a typed DataSet, a table adapter is created for each database table you select. The SelectCommand of the table adapter is set to contain a SQL SELECT statement that retrieves each column in the table. The InsertCommand is set to contain a SQL INSERT statement that inserts into each column that is not auto-generated, where auto-generated columns are those like Access AutoNumber and SQL Server identity columns. The UpdateCommand is set to contain a SQL UPDATE statement that updates each column that is not auto-generated based on the primary key. The DeleteCommand is set to contain a SQL DELETE statement that will delete a record based on the primary key.
The important thing to note here is that the UpdateCommand and DeleteCommand are generated based on the primary key. It has to know which record to update or delete and it's the PK that identifies that record. If there is no PK then there is no way to identify a record so there is no way to know which record to update or delete, so no UpdateCommand or DeleteCommand are generated.
What you need to do is go back to your database and set a PK on each table and then run the Configuration Wizard on your DataSet to regenerate those table adapters. There's rarely a good reason for a table not to have a primary key so there's almost certainly not a good reason for your table(s) not to have one.
-
Feb 23rd, 2015, 08:32 AM
#3
Thread Starter
Fanatic Member
Re: System.InvalidOperationsException
I think I get that. I was wondering what good the primary key was, since it would not auto generate the auto number in the form. I had gotten rid of the primary key back in Access. I will put them back in. I use them anyway.
thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|