Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


Definition of The function Merge_Data :

VB
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


This Doesnt Work.Simply Msgbox("Error! ") appears that means ExecuteNonQuery() retuns 0 . Hence Merge_Data() returns False
Posted
Updated 9-Oct-18 22:38pm
v2
Comments
[no name] 10-Oct-18 3:56am    
Merge_Data should also return True in case no record is deleted, means the value of Records is 0....
Debsbond008 10-Oct-18 4:10am    
No if value of record is 0 then Merge_data should return false. You actully dont understand my question. My question is why ExecuteNonQuery() is returning 0 i.e why data is not deleted?
[no name] 10-Oct-18 4:12am    
Because no match exists between the two tables?
Debsbond008 10-Oct-18 4:34am    
No there is match more than 10 matches
If there is no match why should I waste my time here. There are matches and still its not working . So I described my problem
[no name] 10-Oct-18 14:52pm    
Solve your Problem by yourself, I don't Need your arrogance ;p

1 solution

Remove * from Query

DELETE FROM SUPPORTERS WHERE SUPPORTERS.AADHAAR IN (SELECT MEMBERS.AADHAAR FROM  MEMBERS )
 
Share this answer
 
v3
Comments
Debsbond008 10-Oct-18 4:12am    
First tried that, it also dont dork then Added *.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900