473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to delete values in case of foreign key

How to delete values in case of foreign key?

Please check out the code:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MonthlyFeeDetail.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
  2.  
  3. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  4.  <table id="TABLE1" onclick="return TABLE1_onclick()">
  5.  
  6.        <tr> 
  7.        <td style="height: 396px; background-color:burlywood; width: 508px; font-size: large; color: #990000;">
  8.            <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
  9.                DataFile="~/App_Data/college.mdb" SelectCommand="SELECT * FROM [Year]"></asp:AccessDataSource>
  10.     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataKeyNames ="Month"
  11.                DataSourceID="AccessDataSource1" Font-Size="Large"
  12.                 BorderColor="Silver" CellSpacing="2" 
  13.                AutoGenerateSelectButton="True">
  14.         <Columns>
  15.  
  16.             <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
  17.             <asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" />
  18.         </Columns>
  19.         <HeaderStyle BackColor="Gray" />
  20.     </asp:GridView>
  21.     </td>
  22.     <td style="height: 396px;  background-color: burlywood; width: 1397px; font-size: large; color: #990000;">
  23.         <span style="font-size: 16pt; color: #006699">Fees Record of Students</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  24.         <asp:AccessDataSource ID="AccessDataSource2" runat="server" 
  25.             DataFile="~/App_Data/college.mdb" 
  26.             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"
  27.              DeleteCommand="Delete From MonthlyFee where Class=@Class AND RollNo=@RollNo">
  28.             <SelectParameters>
  29.                 <asp:ControlParameter ControlID="GridView1" Name="Month" 
  30.                     PropertyName="SelectedValue" Type="String" />
  31.             </SelectParameters>
  32.         </asp:AccessDataSource>
  33.         <asp:GridView ID="GridView2" runat="server" 
  34.             AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" AutoGenerateSelectButton ="true"   
  35.             DataSourceID="AccessDataSource2" Font-Size="Large" CellSpacing="2" 
  36.             Height="198px" Width="941px" AllowPaging="True" 
  37.             AutoGenerateColumns="False">
  38.             <Columns>
  39.                 <asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" />
  40.                 <asp:BoundField DataField="RollNo" HeaderText="RollNo" 
  41.                     SortExpression="RollNo" />
  42.                 <asp:BoundField DataField="StuName" HeaderText="StuName" 
  43.                     SortExpression="StuName" />
  44.                 <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
  45.  
  46.                 <asp:BoundField DataField="RecieptNo" HeaderText="RecieptNo" 
  47.                     SortExpression="RecieptNo" />
  48.             </Columns>
  49.             <HeaderStyle BackColor="Gray" BorderColor="Gray" />
  50.         </asp:GridView>
  51.     </td>
  52.     <td style="width: 7368px; height: 396px;">
  53.         &nbsp;
  54.     </td>
  55.     </tr>
  56.     <tr>
  57.  
  58.      <td style="font-size: large; text-align: left; height: 228px; background-color:Silver; width: 508px; color: #990000;" 
  59.             bgcolor="#FF3300">
  60.         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
  61.         <asp:Label ID="Label1" runat="server" Text="Add New Records" style="color: #cc0000"></asp:Label>
  62.         <br />
  63.         <br />
  64.         <asp:Label ID="Label2" runat="server" Text="RollNo"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
  65.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
  66.         <br />
  67.         <asp:Label ID="Label3" runat="server" Text="Month"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  68.         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
  69.         <br />
  70.         <asp:Label ID="Label4" runat="server" Text="StuName"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  71.         <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
  72.         <br />
  73.         <asp:Label ID="Label5" runat="server" Text="Class"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  74.         <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
  75.         <br />
  76.         <asp:Label ID="Label6" runat="server" Text="SubmitFee"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
  77.         <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />
  78.         <br />
  79.         <asp:Label ID="Label7" runat="server" Text="RecieptNo"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  80.         <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
  81.         <br />
  82.          <asp:Button ID="Button1" runat="server" Text="AddNew" onclick="Button1_Click" />
  83.          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  84.          <br />
  85.  
  86.  
  87.     </td>
  88.     </tr>
  89. </table>
  90.  
  91. </asp:Content>
  92.  
  93.  
  94.  
Sep 7 '10 #1
8 2669
dip_developer
648 Expert 512MB
please elaborate your query...........what do you want...??
Sep 8 '10 #2
Like given in the above code:
On select click of 1st grid view table
Values in 2nd grid view appear from some other table.
Now i Have to Delete values in gridview2 on click of delete button.
But The above code shows an exception:"Values for one Or MOre Parameters has not Been Given"

so Please check out
Sep 8 '10 #3
first u have to deleted values for that id in child tables and then after u want to delete entry from parent tables.

if u are directly deleted parent table value then it gives exception because that value or ID uses in its child table.

so batter way is that first u want to delete its child table entry and after deleted parent table entry
Sep 9 '10 #4
Actually the tables are arranged as:
On The basis of first (gridview1) linked to table Year(Year, Month) when arow is selected than the values corresponding to that Month are displayed in GridView2 From Table MonthlyFee(Month,Class,RollNo,Year,Fee)
Now i Have to delete values from 2nd grid view(RollNo is Unique)
Sep 9 '10 #5
if RollNo is the Primary key of your table then u had RollNo use in diffrent table as foreign key...
first check it and if roll no is connected with another tables with foreign key then first delete all recored from those tables which concerned same roll no in primary table..

like examples.
if u want to delete roll no:2 in gridview 2.ok
but roll no-2 is used by another table(s) as a foreign key..
so first check it which table uses roll no-2 and delete all recored from those table(s) where roll no-2 and after delete main table recored(like u have uses in Gridview2)
Sep 9 '10 #6
No friend rollno is not acting as foreign key and
the exception thrown is values for one or more parameter has not been given
Sep 9 '10 #7
mzmishra
390 Expert 256MB
I think the problem is somehwere in your command queries.
Are you able to get the values in both the grids properly.
Sep 9 '10 #8
Yes i have got the values but the exception while deleting is "Values for one or more parameter has not been given"
Sep 12 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Senthilvel Samatharman | last post by:
I am just curious about the case 3 in the follwouing program. I understand that case 1 is the right way to overload, while Case 2 is erroneous. But i do think that the implementation of operator...
1
by: Kathy Burke | last post by:
I know that elements and attribute names are case sensitive, but are the actual attribute values case sensitive when referred to from within an xsl stylesheet for example? Thanks, Kathy ...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
3
by: Daniel Savard | last post by:
Is there a way to define a foreign key for the values of an array? For example, if table T1 is having a colum A which is defined as integer can I define a foreign key in order to force each value...
6
by: Ivan | last post by:
Hello to all and thanks for answer to my topics. I made one stored procedure that delete one table, but when call/execute the procedure this show SQL0532N A parent row cannot be deleted...
8
by: Brian L. Troutwine | last post by:
I've got a problem that I can't seem to get my head around and hoped somebody might help me out a bit: I've got a dictionary, A, that is arbitarily large and may contains ints, None and more...
4
by: kdt | last post by:
Hi Trying to create a function that takes two dictionaries, and deletes key:values that are common in both dictionaries. So far I have the following; but I can only delete values in one dictionary...
6
by: koutoo | last post by:
How do I delete or remove values from a list or string using the index. If a = and I want to get rid of 1 -5, how would I do that? Thanks.
2
by: Sasi Rekha | last post by:
Hi I have Chennai in a textbox and CHENnai in my drop down. When i try to compare those two they are not matching. Is drop down values case sensitive? If so how can i make the drop down list values...
55
by: aarklon | last post by:
Hi, why general integer expressions are not allowed in case labels in switch statements..????
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.