Note that there are some explanatory texts on larger screens.

plurals
  1. PODeleting an entity from a table which is dependent on another table
    text
    copied!<p>I have 2 tables MachineGroups and Machines. MachineGroups has columns:</p> <ul> <li>MachinegroupID</li> <li>MachineGroupName</li> <li>MachineGroupDesc</li> </ul> <p>And Machines has columns:</p> <ul> <li>MachineGroupID (FK)</li> <li>MachineID</li> <li>MachineName</li> <li>Machinedesc</li> </ul> <p>Now I want to delete a machinegroup but not the ones that have machines in it. So if there are machines it should give an error message.... saying you cannot delete.</p> <p>Here is what I am trying to do.....</p> <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="1" CellSpacing="2" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="100%" ondatabound="GridView1_DataBound1" onrowdatabound="GridView1_RowDataBound1"&gt; &lt;RowStyle BackColor="#D0D8E8" ForeColor="#333333" Height="35px" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="MachineGroupID" HeaderText="MachineGroupID" InsertVisible="False" ReadOnly="True" SortExpression="MachineGroupID" Visible="False" /&gt; &lt;asp:BoundField DataField="MachineGroupName" HeaderText="MachineGroupName" SortExpression="MachineGroupName" /&gt; &lt;asp:BoundField DataField="MachineGroupDesc" HeaderText="MachineGroupDesc" SortExpression="MachineGroupDesc" /&gt; &lt;asp:BoundField DataField="TimeAdded" HeaderText="TimeAdded" SortExpression="TimeAdded" /&gt; &lt;asp:TemplateField HeaderText="CanBeDeleted" SortExpression="CanBeDeleted" Visible="False"&gt; &lt;EditItemTemplate&gt; &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# Bind("CanBeDeleted") %&gt;' /&gt; &lt;/EditItemTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID="CheckBox1" runat="server" Checked='&lt;%# Bind("CanBeDeleted") %&gt;' Enabled="false" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="No. of PCs" HeaderText="No. of PCs" ReadOnly="True" SortExpression="No. of PCs" /&gt; &lt;asp:TemplateField ShowHeader="False"&gt; &lt;ItemTemplate&gt; &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"&gt;&lt;/asp:LinkButton&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt; &lt;HeaderStyle BackColor="#4F81BD" Font-Bold="True" ForeColor="White" Height="30px" /&gt; &lt;EditRowStyle BackColor="#999999" /&gt; &lt;AlternatingRowStyle BackColor="#E9EDF4" ForeColor="#284775" /&gt; &lt;/asp:GridView&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:SumooHAgentDBConnectionString %&gt;" SelectCommand="SELECT MachineGroups.MachineGroupID, MachineGroups.MachineGroupName, MachineGroups.MachineGroupDesc, MachineGroups.TimeAdded, MachineGroups.CanBeDeleted, COUNT(Machines.MachineName) AS 'No. of PCs' FROM MachineGroups FULL OUTER JOIN Machines ON Machines.MachineGroupID = MachineGroups.MachineGroupID GROUP BY MachineGroups.MachineGroupID, MachineGroups.MachineGroupName, MachineGroups.MachineGroupDesc, MachineGroups.TimeAdded, MachineGroups.CanBeDeleted" DeleteCommand="DELETE FROM MachineGroups WHERE (MachineGroupID = @original_MachineGroupID) AND (MachineGroupName = @original_MachineGroupName) AND (MachineGroupDesc = @original_MachineGroupDesc) AND (CanBeDeleted = @original_CanBeDeleted) AND (TimeAdded = @original_TimeAdded)"&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name="original_MachineGroupID" /&gt; &lt;asp:Parameter Name="original_MachineGroupName" /&gt; &lt;asp:Parameter Name="original_MachineGroupDesc" /&gt; &lt;asp:Parameter Name="original_CanBeDeleted" /&gt; &lt;asp:Parameter Name="original_TimeAdded" /&gt; &lt;/DeleteParameters&gt; &lt;/asp:SqlDataSource&gt; </code></pre> <p>Please suggest what to do..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload