Hi,
There are two related tables: one called 'group' and the other 'items'. Each
item belongs to a group. The table 'group' is shown in a gridview with a
linkbutton for deleting.
When an user tries to delete a group which still contains items, he gets the
message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groep 1". The conflict occurred in database "tennis", table
"dbo.mytabl e", column 'groupna'.
The statement has been terminated. "
I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.
aspx file:
----------
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" runat="server"
CommandArgument ="<%# Container.DataI temIndex %>"
CommandName="De lete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
....
code-behind:
-----------
....
If e.CommandName = "Delete" Then
Try
Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent
T.
There are two related tables: one called 'group' and the other 'items'. Each
item belongs to a group. The table 'group' is shown in a gridview with a
linkbutton for deleting.
When an user tries to delete a group which still contains items, he gets the
message:
"The DELETE statement conflicted with the REFERENCE constraint
"FK_items_groep 1". The conflict occurred in database "tennis", table
"dbo.mytabl e", column 'groupna'.
The statement has been terminated. "
I want to avoid this and just send a short message in a label. So i tried
this, but the error message still appears.
aspx file:
----------
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" runat="server"
CommandArgument ="<%# Container.DataI temIndex %>"
CommandName="De lete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
....
code-behind:
-----------
....
If e.CommandName = "Delete" Then
Try
Me.SqlDataSourc e1.DeleteComman d = "delete from groep WHERE groepnr='" &
groupkey & "'"
Catch ex As Exception
label1.Text = "Group '" & Server.HtmlEnco de(groupkey) & "' cannot be
removed."
End Try
End If
Thanks
Vincent
T.
Comment