如何从已存在于另一个TABLE中的TABLE中删除数据 [英] How can I delete data from a TABLE that's already exists in another TABLE
问题描述
我正在使用visual studio 2017和ms access for Windows表单应用程序。我有一个会员和一个支持者表。这两个表都有一个coloumn [AADHAAR]。在两个表中,[AADHAAR]是主要的。如果在MEMBERS表的[AADHAAR]列中找到匹配项,我想删除SUPPORTERS表中的所有记录。
我使用了一个执行任务的按钮。
注意:MEMBERS表的[AADHAAR]列和SUPPORTERS表的[AADHAAR]列之间有10个以上的匹配项。仍然ExecuteNonQuery()返回0.所以不发布评论,如没有匹配。 bla ... bla .. bla ..
我尝试过:
I am using visual studio 2017 and ms access 2016 for a Windows forms application. I have a MEMBERS and a SUPPORTERS table. Both of the table has a coloumn [AADHAAR]. In both tables the [AADHAAR] is primary. I want to delete all the records from SUPPORTERS table if a match found with [AADHAAR] column of MEMBERS table.
I have used a button which does the task..
Note: There are more than 10 matches between [AADHAAR] column of MEMBERS table and [AADHAAR] column of SUPPORTERS table. Still ExecuteNonQuery() returns 0. So dont post comments like there is no matches. bla.. bla.. bla..
What I have tried:
private Sub Extra_Btn_Click(sender As Object, e As EventArgs) Handles Extra_Btn.Click
If Merge_Data() = True Then
MsgBox("Duplicate Data removed")
Else
MsgBox("Error! ")
End If
End Sub
函数Merge_Data的定义:
Definition of The function Merge_Data :
Public Function Merge_Data() As Boolean
Try
Link()
cmd.CommandText = "DELETE * FROM SUPPORTERS WHERE SUPPORTERS.AADHAAR IN (SELECT MEMBERS.AADHAAR FROM MEMBERS)"
Records = cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
If Records > 0 Then
Return True
Else
Return False
End If
End Function
这不会工作。只显示Msgbox(错误!)意味着ExecuteNonQuery()返回0。因此,Merge_Data()返回False
This Doesnt Work.Simply Msgbox("Error! ") appears that means ExecuteNonQuery() retuns 0 . Hence Merge_Data() returns False
推荐答案
从查询中删除*
Remove * from Query
DELETE FROM SUPPORTERS WHERE SUPPORTERS.AADHAAR IN (SELECT MEMBERS.AADHAAR FROM MEMBERS )
这篇关于如何从已存在于另一个TABLE中的TABLE中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!