How to delete values in case of foreign key?
Please check out the code:
Please check out the code:
Code:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MonthlyFeeDetail.aspx.cs" Inherits="_Default" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <table id="TABLE1" onclick="return TABLE1_onclick()"> <tr> <td style="height: 396px; background-color:burlywood; width: 508px; font-size: large; color: #990000;"> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/college.mdb" SelectCommand="SELECT * FROM [Year]"></asp:AccessDataSource> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames ="Month" DataSourceID="AccessDataSource1" Font-Size="Large" BorderColor="Silver" CellSpacing="2" AutoGenerateSelectButton="True"> <Columns> <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" /> <asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" /> </Columns> <HeaderStyle BackColor="Gray" /> </asp:GridView> </td> <td style="height: 396px; background-color: burlywood; width: 1397px; font-size: large; color: #990000;"> <span style="font-size: 16pt; color: #006699">Fees Record of Students</span> <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/college.mdb" SelectCommand="SELECT * FROM [MonthlyFee] WHERE ([Month] = ?)" UpdateCommand ="UPDATE MonthlyFee set Month=@Month,RollNo=@RollNo,StuName=@StuName, Class=@Class,SubmitFee=@SubmitFee,RecieptNo=@RecieptNo where Month=@Month" DeleteCommand="Delete From MonthlyFee where Class=@Class AND RollNo=@RollNo"> <SelectParameters> <asp:ControlParameter ControlID="GridView1" Name="Month" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:AccessDataSource> <asp:GridView ID="GridView2" runat="server" AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AutoGenerateSelectButton ="true" DataSourceID="AccessDataSource2" Font-Size="Large" CellSpacing="2" Height="198px" Width="941px" AllowPaging="True" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" /> <asp:BoundField DataField="RollNo" HeaderText="RollNo" SortExpression="RollNo" /> <asp:BoundField DataField="StuName" HeaderText="StuName" SortExpression="StuName" /> <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" /> <asp:BoundField DataField="RecieptNo" HeaderText="RecieptNo" SortExpression="RecieptNo" /> </Columns> <HeaderStyle BackColor="Gray" BorderColor="Gray" /> </asp:GridView> </td> <td style="width: 7368px; height: 396px;"> </td> </tr> <tr> <td style="font-size: large; text-align: left; height: 228px; background-color:Silver; width: 508px; color: #990000;" bgcolor="#FF3300"> <asp:Label ID="Label1" runat="server" Text="Add New Records" style="color: #cc0000"></asp:Label> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="RollNo"></asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label3" runat="server" Text="Month"></asp:Label> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label4" runat="server" Text="StuName"></asp:Label> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label5" runat="server" Text="Class"></asp:Label> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label6" runat="server" Text="SubmitFee"></asp:Label> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br /> <br /> <asp:Label ID="Label7" runat="server" Text="RecieptNo"></asp:Label> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br /> <br /> <asp:Button ID="Button1" runat="server" Text="AddNew" onclick="Button1_Click" /> <br /> </td> </tr> </table> </asp:Content>
Comment