我无法执行删除查询 [英] i can not performed delete query

查看:78
本文介绍了我无法执行删除查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用以下代码执行删除查询



i cant performed delete query by using below code



adp = New SqlDataAdapter("delete from tbl1 where no=" & TextBox1.Text & " ", cn)
        adp1 = New SqlDataAdapter("delete from tbl2 where no=" & TextBox1.Text & "", cn)

        cmd.ExecuteNonQuery()
        'cmd1.ExecuteNonQuery()
        adp.Fill(ds, "tbl1")
        cmd.ExecuteNonQuery()
        adp1.Fill(ds1, "tbl2")
        MsgBox("Record Deleted....")



错误生成

DELETE语句与REFERENCE约束"FK_tbl2_tbl1"冲突.冲突发生在数据库"two",表"dbo.tbl2",列"no"中.该语句已终止.



error generate

The DELETE statement conflicted with the REFERENCE constraint "FK_tbl2_tbl1". The conflict occurred in database "two", table "dbo.tbl2", column ''no''. The statement has been terminated.

推荐答案

您需要先删除 Child 表中的所有引用(记录),然后再从 Master中删除表.

或者您可以参考以下内容:

http://www.builderau.com.au/program/sqlserver/soa/SQL-basics-Deleting-from-child-tables/0,339028455,320269121,00.htm [ http://www.sqlteam.com/article/performing-a- Cascade-delete-in-sql-server-7 [ ^ ]

谢谢,
Imdadhusen
You need to delete before all references (Records) from Child tables then delete from Master table.

Or you may refer following:

http://www.builderau.com.au/program/sqlserver/soa/SQL-basics-Deleting-from-child-tables/0,339028455,320269121,00.htm[^]

http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7[^]

Thanks,
Imdadhusen


如上所述,您必须先删除子行,否则另一种可能性是更改外键约束,以将删除从主表级联到子表.如果希望数据库在删除master时始终删除子节点,则可以使用此方法.请参阅:级联引用完整性约束 [
As said you must delete the child rows first or the other possibility is to change the foreign key constraint to cascade the deletion from master table to child tables. You can use this approach if you want the database to always delete the children when master is deleted. See: Cascading Referential Integrity Constraints[^]


这篇关于我无法执行删除查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆