[英]Deleting columns from multiple table having relationship
I am using Gridview to Display some Data from database and have giving option to delete data But now i just referenced primary key column to another table by foreign key. 我正在使用Gridview从数据库显示一些数据,并提供了删除数据的选项,但是现在我只是通过外键将主键列引用到另一个表中。 Anyway to delete and now delete is not working because of conflict. 无论如何删除,现在由于冲突而无法删除。
Error:-The DELETE statement conflicted with the REFERENCE constraint "FK_temp1_ProductDetails". 错误:-DELETE语句与REFERENCE约束“ FK_temp1_ProductDetails”冲突。 The conflict occurred in database "E:\\VISUAL STUDIO 2010\\SHOPMOBILE\\APP_DATA\\SHOPPING.MDF", table "dbo.temp1", column 'product_id'. 在数据库“ E:\\ VISUAL STUDIO 2010 \\ SHOPMOBILE \\ APP_DATA \\ SHOPPING.MDF”的表“ dbo.temp1”的“ product_id”列中发生了冲突。 The statement has been terminated. 该语句已终止。
Anyway to delete data from both the table on same time.Delete query is 无论如何要同时从两个表中删除数据。删除查询是
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:shoppingConnectionString2 %>"
DeleteCommand="DELETE FROM [ProductDetails] WHERE [Product_id] = @original_Product_id"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [ProductDetails]"
UpdateCommand="UPDATE [ProductDetails] SET [Product_name] = @Product_name, [Brand] = @Brand, [Category] = @Category, [Sub_category] = @Sub_category, [Product_info] = @Product_info, [Price] = @Price, [Big_img] = @Big_img, [Quantity] = @Quantity WHERE [Product_id] = @original_Product_id">
<DeleteParameters>
<asp:Parameter Name="original_Product_id" Type="Int32" />
<asp:Parameter Name="original_Product_name" Type="String" />
<asp:Parameter Name="original_Brand" Type="String" />
<asp:Parameter Name="original_Category" Type="String" />
<asp:Parameter Name="original_Sub_category" Type="String" />
<asp:Parameter Name="original_Product_info" Type="String" />
<asp:Parameter Name="original_Price" Type="Int64" />
<asp:Parameter Name="original_Big_img" Type="String" />
<asp:Parameter Name="original_Quantity" Type="Int64" />
</DeleteParameters>
</asp:SqlDataSource>
On sql server management studio, select ProductDetails table design view and open relationships window, then set delete action to CASCADE DELETE, It's works fine. 在sql server management studio上,选择ProductDetails表设计视图并打开关系窗口,然后将delete操作设置为CASCADE DELETE,就可以了。
UPDATE: set it for all table relationships. 更新:为所有表关系设置它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.