Reputation: 240
Got a gridview bound to a LinqDataSource which is getting its data from a MsSQL database view.
This view is pulling in various tables to produce the list I want. This is all working fine.
However, I cannot delete, when I try and use delete I get the error message: Can't perform Create, Update, or Delete operations on 'Table(vwMyView)' because it has no primary key. Well there are a number of tables in there that do have primary keys and I've set the GridView to the DatakeyName I'd like to use in this case 'inID'.
My LDS looks like this:
<asp:LinqDataSource runat="server" ID="ldsMain" EnableDelete="True" ContextTypeName="MyCode.Classes.Data.MyDataContext" OrderBy="inFirstName" OnDeleting="ldsMain_OnDeleting" TableName="MyView"></asp:LinqDataSource>
Have even tried removing the OnDeleting.
I need it to delete direct from the main table which would MyTable and not the View, so how can I do this?
Upvotes: 1
Views: 711
Reputation:
Let's take a step back...Is this a read-only or updatable view?
If the view is read-only then you need to reconfigure your LinqDataSource to reference MyTable and not the view. However, if it is an updatable view then you can perform INSERT, UPDATE, and DELETE operations.
Upvotes: 0
Reputation: 1015
Did you try the following properties in the GridView
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
Upvotes: 0